Tap here to switch tabs
Problem
Ask
Submissions

Problem: Zigzag Conversion

med
30 min
Explore how to rearrange characters of a string in a zigzag pattern across a given number of rows, then read and output the string row-by-row. This lesson helps you understand the pattern recognition needed to implement efficient string manipulation and solve related coding interview problems effectively.

Statement

Given a string s and an integer numRows, rearrange the characters of s by writing them in a zigzag pattern across numRows rows, then reading the result row by row from top to bottom.

For example, writing "COMPUTER" in a zigzag pattern across 3 row produces:

C U
O P T R
M E

This will be read as "CUOPTRME".

Constraints:

  • 11 \leq s.length 1000\leq 1000

  • s consists of English letters (lower-case and upper-case), ',' and '.'.

  • 11 \leq numRows 1000\leq 1000

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Zigzag Conversion

med
30 min
Explore how to rearrange characters of a string in a zigzag pattern across a given number of rows, then read and output the string row-by-row. This lesson helps you understand the pattern recognition needed to implement efficient string manipulation and solve related coding interview problems effectively.

Statement

Given a string s and an integer numRows, rearrange the characters of s by writing them in a zigzag pattern across numRows rows, then reading the result row by row from top to bottom.

For example, writing "COMPUTER" in a zigzag pattern across 3 row produces:

C U
O P T R
M E

This will be read as "CUOPTRME".

Constraints:

  • 11 \leq s.length 1000\leq 1000

  • s consists of English letters (lower-case and upper-case), ',' and '.'.

  • 11 \leq numRows 1000\leq 1000