PIXELBANKv9.1.0
Menu

The string is written in a zigzag pattern on a given number of rows. Read line by line to produce the output.

Example: "PAYPALISHIRING" with 3 rows becomes:

P   A   H   N
A P L S I I G
Y   I   R

Result: "PAHNAPLSIIGYIR"

Example:

Input:
PAYPALISHIRING
3
Output:
PAHNAPLSIIGYIR
Reasoning:
  • The input string "PAYPALISHIRING" is written in a zigzag pattern on 33 rows.
  • The characters are filled row by row, resulting in the following pattern:
P   A   H   N
A P L S I I G
Y   I   R
  • Reading the characters line by line produces the output string: "PAHNAPLSIIGYIR".
  • The final output is "PAHNAPLSIIGYIR" by concatenating the characters from each row.

Constraints:

  • 1 <= len(s) <= 1000
  • 1 <= numRows <= 1000
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Zigzag Conversion - Medium | PixelBank