Undo the Column Read
Someone took a text, wrote it into a grid with k characters per row (filling row after row, so only the last row could be shorter), and then read the grid one column at a time, each column from top to bottom, leftmost column first. t is what they read. Recover and return the original text.
For example t = "hloel" with k = 2 came from "hello": its rows were he, ll and o, and its columns hlo and el. The original text is always unique, and an empty t gives "".
Example 1
Five characters in rows of 2 make 3 rows with a short last row, so the first column has 3 entries and the second has 2: hlo fills column one and el column two, which reads back row by row as hello.
Example 2
Seven characters in rows of 3 make 3 rows; only the first column has 3 entries, the other two have 2. Handing out adgbecf column by column with those heights rebuilds abcdefg.
Constraints
0 <= len(t) <= 601 <= k <= 10thas lowercase letters and digits only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.