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
Be the first one to answer
Add answer anonymously...
Top SAP Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app