Decode the Slanted Ciphertext
A string originalText is encoded into encodedText using a slanted transposition cipher and a matrix with a fixed number of rows, rows.
originalText is written first from the top-left toward the bottom-right.

The blue cells are filled first, then the red cells, then the yellow cells, and so on until every character of originalText has been placed. The arrow shows the fill order. Empty cells are filled with ' '. The number of columns is chosen so that the rightmost column is not empty after originalText is placed.
encodedText is then created by reading and appending the matrix row by row.

The characters in the blue cells are appended first to encodedText, followed by the red cells, then the remaining colors in order. The arrow shows the order in which cells are read.
For example, if originalText = "cipher" and rows = 3, the encoding is shown below.

The blue arrows show how originalText is placed in the matrix, while the red arrows show how encodedText is formed. In this example, encodedText = "ch ie pr".
Given the encoded string encodedText and the number of rows rows, return the original string originalText.
Note: originalText has no trailing spaces ' '. The test cases are generated so that only one valid originalText exists.
Input: encodedText = "ch ie pr", rows = 3
Output: "cipher"
Explanation: This is the same example described in the problem description.

Input: encodedText = "ivmd epe l ov oil", rows = 4
Output: "i love impoldev"
Explanation: The figure above denotes the matrix that was used to encode originalText. The blue arrows show how we can find originalText from encodedText.

Input: encodedText = "coding", rows = 1
Output: "coding"
Explanation: Since there is only 1 row, both originalText and encodedText are the same.
Constraints
0 <= encodedText.length <= 10^6encodedTextconsists of lowercase English letters and' 'only.encodedTextis a valid encoding of someoriginalTextthat does not have trailing spaces.1 <= rows <= 1000- The testcases are generated such that there is only one possible
originalText.
Did this problem appear in one of your interviews?
Responses stay private.
