216. ZigZag Conversion

MediumStringString

Given a string s and numRows, write the characters in a zigzag pattern across the given number of rows, then read row by row to produce the converted string. Input: '"s", numRows'.

Input: '"s", numRows'.

Output: Quoted string — the zigzag conversion.

Examples

Example 1
Input: "PAYPALISHIRING", 3
Output: "PAHNAPLSIIGYIR"
Explanation: 3-row zigzag read by rows.
Example 2
Input: "PAYPALISHIRING", 4
Output: "PINALSIGYAHRPI"
Explanation: 4-row zigzag.
Example 3
Input: "A", 1
Output: "A"
Explanation: Single row.

Constraints

Asked by

AmazonBloombergGoogleOracleMicrosoftInfosys
Solve this problem in the editor →