Zigzag Conversion
MediumArrays & Hashing
Decode it first. Clues, constraints, pattern and plan before any code.Write the characters of s across rows rows in a zigzag: the first character goes on row 0, the next on row 1, and so on down to the last row, then the path turns and goes back up one row at a time to row 0, then down again, until the string runs out. Return the rows read one after another, top row first.
For s = "ABCDEFGH" and rows = 3 the zigzag looks like this:
A E
B D F H
C Gs = "ABCDEFGH", rows = 3 → "AEBDFHCG"
s = "ABCDEFGH", rows = 2 → "ACEGBDFH"
s = "ABCDEFGH", rows = 1 → "ABCDEFGH"Constraints
1 <= s.length <= 10001 <= rows <= 1000scontains English letters, digits,,and..