Read Down the Columns
Write the characters of s into a grid row by row, k characters per row, so that only the last row can be shorter. Then read the grid column by column: the whole first column from top to bottom, then the second column, and so on. Return the string read this way.
For example "abcdefg" with k = 3 gives the rows abc, def and g; reading down the columns gives "adgbecf". When k >= len(s) there is a single row and the answer is s itself. An empty s gives "".
Example 1
s "abcdefg"
k 3
returns "adgbecf"
The columns are adg, be and cf, read in that order.
Example 2
s "abcdef"
k 2
returns "acebdf"
The rows are ab, cd, ef; the columns are ace and bdf.
Constraints
0 <= len(s) <= 601 <= k <= 10shas lowercase letters and digits only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.