Zig-Zag Conversion
You are given a string ‘S’ and an integer ‘ROW’, convert the row into a zig-zag pattern with rows equal to ‘ROW’ and output it row-wise. You may refer to the example below to better understand what the zig-zag pattern means.
Example :
If ‘S’ = “beaninjacoder” and ‘ROW’ = 4
Then the zig-zag pattern is:
b j r
e n a e
a i c d
n o
Therefore, we will print “bjrenaeaicdno”.
Input Format :
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first line of each test case contains a string ‘S’, denoting the input string.
The second line of each test case contains a single integer ‘ROW’, denoting the number of rows in the zig-zag pattern to be created.
Output Format :
For each test case, print the new string after zig-zag conversion.
Output for each test case will be printed in a separate line.
Note :
You are not required to print anything; it has already been taken care of. Just implement the function.
Constraints :
1 ≤ ‘T’ ≤ 10
1 ≤ |S| ≤ 10000
1 ≤ ‘ROW’ ≤ 10000
S only contains lower case English alphabets
Time limit: 1 sec
CodingNinjas
author
2y
Pattern Formation
Consider the case where the number of rows is equal to 10, and everything has a 0 based indexing. In that case, the input string's indexes form the given pattern:
Here Step-2 involves ...read more
Help your peers!
Add answer anonymously...
Top Freshworks Lead Software Engineer interview questions & answers
Popular interview questions of Lead Software Engineer
Top HR questions asked in Freshworks Lead Software Engineer
>
Freshworks Lead Software Engineer Interview Questions
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