Zigzag Conversion
Write the characters of s in a zigzag down and up over numRows rows: go down one row at a time to the last row, then up one row at a time to the first, and repeat. Then read the rows one after another, from the top row to the bottom row, left to right, and return that string.
For "PAYPALISHIRING" with 3 rows the rows are PAHN, APLSIIG, YIR, so the answer is PAHNAPLSIIGYIR. If numRows is 1, return s.
Example 1
s "PAYPALISHIRING"
numRows 3
returns "PAHNAPLSIIGYIR"
Row 0 PAHN, row 1 APLSIIG, row 2 YIR.
Example 2
s "ABCD"
numRows 2
returns "ACBD"
Row 0 AC, row 1 BD.
Constraints
1 <= len(s) <= 1001 <= numRows <= 10
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.