Skip to content

Practice Decode the Slanted Ciphertext

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2075
LeetCode Problem

Decode the Slanted Ciphertext

Problem Statement

The original text is written into a matrix with rows rows by following diagonals downward and rightward, starting successively at each column of the top row. Unfilled cells contain spaces, and the rightmost column contains an original-text character. Reading the matrix row by row produces encodedText. Recover and return the unique original text; it has no trailing spaces. Preserve spaces within the original text.

Source: Decode the Slanted Ciphertext on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
encodedText = "ch   ie   pr", rows = 3
Output
"cipher"

# Example 2

Input
encodedText = "iveo    eed   l te   olc", rows = 4
Output
"i love leetcode"

# Example 3

Input
encodedText = "coding", rows = 1
Output
"coding"

Constraints

0 <= encodedText.length <= 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 <= rows <= 1000
The testcases are generated such that there is only one possible originalText.

Related LeetCode Problems

Practice more problems similar to Decode the Slanted Ciphertext.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.