Problems > Zigzag Diagonals

Zigzag Diagonals

Difficulty: 1300 2000 ms 128 MB

implementation

Print the matrix in diagonal zigzag order: the first anti-diagonal goes UP-RIGHT, the second DOWN-LEFT, alternating (like JPEG's zigzag scan).

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

Output: all values in zigzag-diagonal 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 4 7 5 3 6 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.