You’re given encodedText produced by writing originalText into a matrix with a fixed number of rows, filling diagonally (top-left → bottom-right), padding remaining cells with spaces, choosing cols so the last column isn’t empty, then reading the matrix row-wise to form encodedText.
Given encodedText and rows, return the unique originalText (with no trailing spaces).
Decoding idea:
Let cols = len(encodedText) // rows.
Recreate the rows × cols matrix by filling it row-wise from encodedText.
Read back along diagonals: for each column c from 0..cols-1, take cells (r, c+r) for r = 0..rows-1 while c+r < cols.
Join and rstrip() to remove trailing spaces.
Input: encodedText = "p rgor arming" rows = 4
Output: "programming"
Explanation:
Matrix (4 rows): p r g r a r g m i n g Reading diagonally: "programming".
Input: encodedText = "ivseeh ec c l ut owb"
Output: "i love wscube tech"
Explanation:
Matrix (4 rows): ivseeh ec c l ut owb Reading diagonally: "i love wscube tech".
Accepted:
Submission: