Zig-Zag String Problem Statement
Given a string STR
of size N
and an integer M
representing the number of rows in the zig-zag pattern, return the string formed by concatenating all rows when the string STR
is written in a row-wise zig-zag pattern.
Example:
Input:
N = 12, M = 3, STR = 'CODINGNINJAS'
Output:
'CNNOIGIJSDNA'
Explanation:
When arranged in a zig-zag pattern with 3 rows, the rows contain the following letters: Row 1: 'CNN', Row 2: 'OIGIJS', Row 3: 'DNA'. Concatenating these rows gives the result: 'CNNOIGIJSDNA'.
Constraints:
1 <= T <= 10^2
1 <= N <= 10^3
1 <= M <= N
STR
contains only uppercase letters ('A-Z').- Time Limit: 1 second

AnswerBot
4mo
Arrange a string in zig-zag pattern with given number of rows and concatenate the rows.
Iterate through the string and distribute characters to rows based on zig-zag pattern
Concatenate the characters i...read more
Help your peers!
Add answer anonymously...
SAP Software Developer interview questions & answers
A Software Developer was asked 9mo agoQ. Implement a stack using queues.
A Software Developer was asked 9mo agoQ. Write a function that reverses a string.
A Software Developer was asked 10mo agoQ. Implement a stack using other data structures.
Popular interview questions of Software Developer
A Software Developer was asked 5mo agoQ1. If you have 1 million requests, how will you manage that?
A Software Developer was asked 9mo agoQ2. Implement a stack using queues.
A Software Developer was asked 9mo agoQ3. Write a function that reverses a string.
Top HR questions asked in SAP Software Developer
A Software Developer was asked 8mo agoQ1. Introduce yourself.
A Software Developer was asked 10mo agoQ2. What is your top priority when choosing a new job?
A Software Developer was asked 10mo agoQ3. Tell me about your current project and the technologies you are using.
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

