Peeush Agarwal > Engineer. Learner. Builder.

I am a Machine Learning Engineer passionate about creating practical AI solutions using Machine Learning, NLP, Computer Vision, and Azure technologies. This space is where I document my projects, experiments, and insights as I grow in the world of data science.

View on GitHub

ZigZag conversion

Problem Statement

Given a string, write it in a zigzag pattern on a given number of rows and then read the result line by line.

For example, the string "PAYPALISHIRING" written in a zigzag pattern with 3 rows looks like:

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

Reading line by line gives: "PAHNAPLSIIGYIR".

Implement the following function:

def convert(s: str, numRows: int) -> str:

Examples

Example 1:

Example 2:

Example 3:

Constraints

Code Template

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        # Write your code here
        pass

Solutions

Back to Problem List Back to Categories