/6. Zigzag String Row Conversion

6. Zigzag String Row Conversion

Medium
Strings53.7% acceptance

Given a string input_string and an integer row_count, arrange the characters of input_string in a zigzag pattern across row_count rows. Then, concatenate the characters row by row to produce the final string. Return this resulting string.

Example 1

Input: input_string=HELLOPYTHON, row_count=3

Output: HLOEYPHTLON

Explanation: Zigzag arrangement: H L O E L P Y T H L O N Read row by row: HLOEYPHTLON

Example 2

Input: input_string=ABCD, row_count=2

Output: ACBD

Explanation: Zigzag arrangement: A B C D Read row by row: ACBD

Example 3

Input: input_string=Z, row_count=1

Output: Z

Explanation: Only one row, so output is the input.

Constraints

  • 1 <= len(input_string) <= 1000
  • input_string consists of English letters (lower-case and upper-case), , and .
  • 1 <= row_count <= 1000
Python (current runtime)

Case 1

Input: input_string='PROGRAMMING', row_count=4

Expected: 'PMRAGGINORM'

Case 2

Input: input_string='DATA,SCIENCE.', row_count=5

Expected: 'D,ENCT.AAISCA'

Case 3

Input: input_string='ALGORITHM', row_count=2

Expected: 'AORTILGHM'

Case 4

Input: input_string='X', row_count=1

Expected: 'X'

Case 5

Input: input_string='PYTHON', row_count=6

Expected: 'PYTHON'