/6. Zigzag String Transformation

6. Zigzag String Transformation

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 concatenated string.

Example 1

Input: input_string=HELLOPYTHON, row_count=3

Output: HOYELTNLPTHO

Explanation: Rows: H O Y E L T N L P L P T H O

Example 2

Input: input_string=DATA,SCIENCE., row_count=4

Output: DSE.AAICNTC,

Explanation: Rows: D S E A A I C N T C , . .

Example 3

Input: input_string=Z, row_count=1

Output: Z

Explanation: Single row, output is 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='ALGORITHM', row_count=2

Expected: 'AGOTIRLHM'

Case 2

Input: input_string='COMPUTER', row_count=5

Expected: 'CRUOMPTAE'

Case 3

Input: input_string='PYTHON', row_count=6

Expected: 'PYTHON'

Case 4

Input: input_string='OPENAI', row_count=3

Expected: 'OEAIPN'