Problems > Boustrophedon

Boustrophedon

Difficulty: 1000 2000 ms 128 MB

implementation

Print the matrix in snake order: row 1 left-to-right, row 2 right-to-left, alternating.

Input: the first line has N and M; the next N lines each have M integers.

Output: all values in snake order on one line.

Constraints:

  • 1 ≤ N, M ≤ 100

Sample Tests

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.