Mark As Completed Discussion

Good morning! Here's our prompt for today.

Encryption means encoding a string using some pre-defined formula. It is widely used for securing and protecting sensitive information over the internet from theft and data breaches.

Suppose an English text has to be encrypted using the following procedure for encoding:

  1. Remove all the whitespaces from the text.
  2. Then, the characters are laid down in a grid/matrix using the following constraints:

Constraints

  • L is the length of the string
  • ⌊√L⌋ ≤ row ≤ column ≤ ⌈√L⌉, where ⌊𝔁⌋ is a floor function, and ⌈𝔁⌉ is a ceiling function
  • The string will only contain alphabetic characters (a-z, A-Z)
  • rows x columns ≥ L
  • If multiple grids satisfy the condition, choose the one with minimum area, rows x columns

Example

Let’s say we have a string “a quick brown fox jumps over the fence.” After removing spaces, we have L = 31, and can calculate that the √L value is between 5 and 6, so the resulting grid would have 5 rows and 6 columns like below:

SNIPPET
1aquick
2brownf
3oxjump
4soverth
5efence

Expected Output

The output would be a string displaying characters in each column, separated by whitespaces. So the string will display characters from the first column followed by a whitespace, and then the second column followed by a whitespace, and so on…

Here’s how the output will look like for the example string given above:

“aboshe qrxoe uojvf iwuee cnmrn kfptc”

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Here's our guided, illustrated walk-through.

How do I use this guide?

Access all course materials today

The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

Returning members can login to stop seeing this.