Zig-Zag Conversion Problem Statement
You are given a string S
and an integer ROW
. Your task is to convert the string into a zig-zag pattern on a given number of rows. After the conversion, output the string row-wise.
Refer to the example below for better understanding of how the zig-zag pattern should be arranged.
Example:
Input:
S = "beaninjacoder", ROW = 4
Output:
"bjrenaeaicdno"
Explanation:
The zig-zag pattern is: b j r e n a e a i c d n o Therefore, outputs row-wise result in the string "bjrenaeaicdno".
Constraints:
1 ≤ T ≤ 10
1 ≤ |S| ≤ 10000
1 ≤ ROW ≤ 10000
S
only contains lowercase English alphabets- Time limit: 1 sec

AnswerBot
4mo
Convert a given string into a zig-zag pattern on a specified number of rows and output the result row-wise.
Iterate through the string and place characters in the zig-zag pattern based on the row numbe...read more
Help your peers!
Add answer anonymously...
Freshworks Lead Software Engineer interview questions & answers
A Lead Software Engineer was asked 3mo agoQ. Given a string, find all palindromes within it.
A Lead Software Engineer was asked 3mo agoQ. How do you reverse a linked list?
A Lead Software Engineer was asked 8mo agoQ. Elevator travel, find the no. of hops
Popular interview questions of Lead Software Engineer
A Lead Software Engineer was asked 3mo agoQ1. Given a string, find all palindromes within it.
A Lead Software Engineer was asked 8mo agoQ2. Elevator travel, find the no. of hops
A Lead Software Engineer was asked 11mo agoQ3. Given an array of integers, find all unique triplets (a, b, c) such that a + b +...read more
>
Freshworks Lead Software Engineer Interview Questions
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

