January 16, 2025 |3.8K Views

Print Concatenation of Zig-Zag String in ‘n’ Rows

Description
Discussion

Input: str = “PAYPALISHIRING”, N = 3
Output: PAHNAPLSIIGYIR

Input: str = “ABCDEFGH”, N = 2
Output: ACEGBDFH
Explanation: The input string can be written in Zig-Zag fashion in 2 rows as follows:
A   C    E   G    
  B   D   F   H
Hence, upon reading the above pattern row-wise, the output string is “ACEGBDFH”

Print Concatenation of Zig-Zag String in ‘n’ Rows : https://www.geeksforgeeks.org/concatenation-of-zig-zag-string-in-n-rows/