Description

Write a string in a zigzag pattern on a given number of rows (going down then up), then read line by line to produce the output.

Examples

Input:s = "PAYPALISHIRING", numRows = 3
Output:"PAHNAPLSIIGYIR"
Explanation:

Zigzag pattern with 3 rows.

Input:s = "a", numRows = 3
Output:"PAHNAPLSIIGYIR"
Explanation:

Edge case with a single character.

Input:s = "HELLO", numRows = 4
Output:"HOELL"
Explanation:

With 4 rows, the zigzag pattern places characters: Row 0: H (index 0), Row 1: E (index 1), Row 2: L (index 2), Row 3: L (index 3), then going up: Row 2: O (index 4). Reading row by row gives: Row 0: 'H', Row 1: 'E', Row 2: 'LO', Row 3: 'L', resulting in 'HOELL'.

Constraints

  • 1 ≤ s.length ≤ 1000
  • 1 ≤ numRows ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!