"PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this:
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:
string convert(string s, int numRows)
Example 1:
Input: s = "PAYPALISHIRING", numRows = 4
Output: "PINALSIGYAHRPI"
Explanation:
P I N
A L S I G
Y A H R
P I
Constraints:
1 <= s.length <= 1000
s consists of English letters (lower-case and upper-case), ',' and '.'.
1 <= numRows <= 1000
Could you draw it out in an 2D array?
For better space complexity, what are the gaps in between the elements in each row? Can you use this to traverse the string without building a 2D array?
What are the space and time complexity for these solutions?