The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR". Write the code that will take a string and make this conversion given a number of rows.
Example 1
Input: s = PAYPALISHIRING, numRows = 3
Output: PAHNAPLSIIGYIR
Explanation: Writing the letters down and diagonally up across 3 rows gives "PAHN", "APLSIIG" and "YIR". Reading the rows in order gives "PAHNAPLSIIGYIR".
Example 2
Input: s = PAYPALISHIRING, numRows = 4
Output: PINALSIGYAHRPI
Explanation: With 4 rows the zigzag rows read "PIN", "ALSIG", "YAHR" and "PI". Joined together that is "PINALSIGYAHRPI".
Example 3
Input: s = A, numRows = 1
Output: A
Explanation: With only one row there is no zigzag, so the string stays "A".
Walk through the string appending each character to the current row, bouncing the row index up and down between the top and bottom rows. Concatenating the rows top to bottom gives the zigzag reading.
Run checks all cases above. Submit evaluates all test cases.