Back to DSA

Zigzag Conversion

medium
Acceptance: 50%
Strings

A string is to be laid out in a zigzag pattern across a specified number of horizontal rows, then read back row by row from top to bottom. Implement a function that takes the original string and the row count, and returns the string obtained by reading the zigzag arrangement left to right, top to bottom.

Examples

Example 1:
Input:s = "HELLOWORLD", numRows = 3
Output:"HOLELWRDLO"
Explanation: Row 0: H O L, Row 1: E L W R D, Row 2: L O. Concatenating all rows yields 'HOLELWRDLO'.
Example 2:
Input:s = "AB", numRows = 1
Output:"AB"
Explanation: With only one row, the string is unchanged.

Hints

00:00
1234567