Return in Row wave form

Given a 2D integer array, write a method that read rows of the matrix alternatively from left to right and right to left and return them as a 1 dimensional array.

That is, read 1st row from left to right, 2nd row from right to left, 3rd row from left to right and so on and save then in 1D array.

Input format :

Line 1 : No. of rows & No. of columns (separated by space)

Line 2 : Row 1 elements (separated by space)

Line 3 : Row 2 elements (separated by space)

Line 4 : and so on

Sample Input 1 :
3 3
1 2 3 
4 5 6 
7 8 9 
Sample Output 1 :
1 2 3 6 5 4 7 8 9

Login to submit your solution

Fb dab53a1a64929320dc7425896aa73fd9e5512b6ab52e414ff5f3ebb5cecc73eb

Share Problem