Given a string and number of rows ‘n’. Print the string formed by concatenating n rows when input string is written in row-wise Zig-Zag fashion.
Input: str = "ABCDEFGH" n = 2 Output: "ACEGBDFH" Explanation: Let us write input string in Zig-Zag fashion in 2 rows. A C E G B D F H Now concatenate the two rows and ignore spaces in every row. We get "ACEGBDFH" Input: str = "GEEKSFORGEEKS" n = 3 Output: GSGSEKFREKEOE Explanation: Let us write input string in Zig-Zag fashion in 3 rows. G S G S E K F R E K E O E Now concatenate the two rows and ignore spaces in every row. We get "GSGSEKFREKEOE"
The first line of input consists number of the test cases. The description of T test cases is as follows:
The first line of each test case contains the string, and the second line has 'n' the number of rows.
In each separate line print the string after concatenating n rows in a zig zag form.
1 ≤ T ≤ 70
1 ≤ N ≤ size of string
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.