ZigZag Conversion
Medium · Online assessment (OA) · Full-time
ZigZag conversion came up early in my PayPal phone interview. Write a string in a zigzag pattern across n rows and read it back line by line. I used an array of string builders, one per row, and bounced a direction variable when hitting the top or bottom row. The interviewer asked about the pattern of indices for each row and whether I could compute the output directly without simulating the zigzag. We worked through the math for the cycle length being 2*numRows - 2.
