Zigzag Conversion

Medium

Company Tags

You are given a string s and a positive integer numRows. Return the string after converting it to zig-zag pattern.

The string "GOOGLEISHIRING" is written in a zigzag pattern on a given number of rows numRows=3 like this: (you may want to display this pattern in a fixed font for better legibility)

G   L   H   N
O G E S I I G
O   I   R

And then read line by line: "GLHNOGESIIGOIR"

Example 1:

Input: s = "GOOGLEISHIRING", numRows = 4

Output: "GINOESIGOLHRGI"

Explanation:

G    I    N
O  E S  I G
O L  H R
G    I

Example 2:

Input: s = "GOOGLEISHIRING", numRows = 5

Output: "GHOSIOIRGEIGLN"

Explanation:

G     H
O   S I
O  I  R
G E   I G
L     N

Constraints:

  • 1 <= s.length, numRows <= 1000
  • s consists of English letters (lower-case and upper-case), ',' and '.'.


Company Tags

Please upgrade to NeetCode Pro to view company tags.

s =

numRows =