Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Matrix Encryption (Main Thread)

Here is the interview question prompt, presented for reference.

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:

aquick
brownf
oxjump
soverth
efence

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”

You can see the full challenge with visuals at this link.

Challenges • Asked over 2 years ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on May 17, 2022:

This is the main discussion thread generated for Matrix Encryption (Main Thread).