Tap here to switch tabs
Problem
Submissions

Problem: Decode the Slanted Ciphertext

med
30 min
Try to solve the Decode the Slanted Ciphertext problem.

Statement

A string originalText is encoded using a slanted transposition cipher onto a matrix with a given number of rows.

The encoding process works as follows:

  1. A matrix is formed with rows rows and a number of columns such that originalText fits completely.

  2. Characters of originalText are filled diagonally starting from the top row, moving from cell (r,c)(r, c) to cell (r+1,c+1)(r + 1, c + 1). When the bottom row is reached, the next diagonal begins at the next column in the top row.

  3. Any unused cells in the matrix are filled with spaces ' '.

  4. The encoded string encodedText is formed by reading the matrix row by row from top to bottom, from left to right.

Given the encoded string encodedText and the integer rows, return the decoded string originalText.

Note: The originalText does not have any trailing spaces.

Constraints:

  • 0≤0 \leq encodedText.length ≤106\leq 10^6

  • encodedText consists of lowercase English letters and ' ' only.

  • encodedText is a valid encoding of some originalText that does not have trailing spaces.

  • 1≤1 \leq rows ≤1000\leq 1000

  • The testcases are generated such that there is only one possible originalText.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Decode the Slanted Ciphertext

med
30 min
Try to solve the Decode the Slanted Ciphertext problem.

Statement

A string originalText is encoded using a slanted transposition cipher onto a matrix with a given number of rows.

The encoding process works as follows:

  1. A matrix is formed with rows rows and a number of columns such that originalText fits completely.

  2. Characters of originalText are filled diagonally starting from the top row, moving from cell (r,c)(r, c) to cell (r+1,c+1)(r + 1, c + 1). When the bottom row is reached, the next diagonal begins at the next column in the top row.

  3. Any unused cells in the matrix are filled with spaces ' '.

  4. The encoded string encodedText is formed by reading the matrix row by row from top to bottom, from left to right.

Given the encoded string encodedText and the integer rows, return the decoded string originalText.

Note: The originalText does not have any trailing spaces.

Constraints:

  • 0≤0 \leq encodedText.length ≤106\leq 10^6

  • encodedText consists of lowercase English letters and ' ' only.

  • encodedText is a valid encoding of some originalText that does not have trailing spaces.

  • 1≤1 \leq rows ≤1000\leq 1000

  • The testcases are generated such that there is only one possible originalText.