ZigZag Conversion

Easy Solved

Description

Convert string s into a zigzag pattern on numRows rows. Then read line by line. Return the converted string.

Example 1:

Input: s = "PAYPALISHIRING", numRows = 3

Output: "PAHNAPLSIIGYIR"

Example 2:

Input: s = "PAYPALISHIRING", numRows = 4

Output: "PINALSIGYAHRPI"

Example 3:

Input: s = "A", numRows = 1

Output: "A"

Note:

Runner uses stdin: first line is the input string, second line is the integer numRows (e.g.PAYPALISHIRING\n3). Program must print final string.

Your Submissions

No submissions yet.

Discuss

Talk about row-wise simulation, index math, time/space tradeoffs.

Test Cases

Test Case 1
Test Case 2
Test Case 3