Back to course home
0% completed
Vote For New Content
Zigzag Conversion (medium)
Problem Statement
Given a string s
and a numRows
integer representing the number of rows, write the string in a zigzag
pattern on the given number of rows
and then read it line by line, and return the resultant string.
The zigzag pattern means writing characters in a diagonal down-and-up fashion. For example, given the string "HELLOPROGRAMMING" and 4 rows, the pattern would look like:
H R M
E P O M I
L O G A N
L R G
Reading it line by line gives us "HRMEPOMILOGANLRG".
Examples
Example 1:
- Input:
s = "HELLOPROGRAMMING", numRows = 4
- Expected Output:
"HRMEPOMILOGANLRG"
- Explanation: The zigzag pattern is:
Reading line by line gives "HRMEPOMILOGANLRG".H R M E P O M I L O G A N L R G
Example 2:
- Input:
s = "PROBLEMCHALLENGE", numRows = 5
- Expected Output:
"PHRCAEOMLGBELNLE"
- Explanation: The zigzag pattern is:
Reading line by line gives "LCCETEHLDELOEGAEEN".P H R C A E O M L G B E L N L E
Example 3:
- Input:
s = "ABCDE", numRows = 2
- Expected Output:
"ACEBD"
- Explanation: The zigzag pattern is:
Reading line by line gives "ACEBD".A C E B D
Constraints:
- 1 <= s.length <= 1000
s
consists of English letters (lower-case and upper-case), ',' and '.'.- 1 <= numRows <= 1000
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible