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
Be the first one to answer
Add answer anonymously...
Freshworks Lead Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter