Facebook | Onsite | Matrix Antidiagonal Traverse
8332

Given a matrix, return all elements of the matrix in antidiagonal order as shown in the below image.

Example 1:

Input:
[[12, 7, 21, 31, 11],
 [45, -2, 14, 27, 19],
 [-3, 15, 36, 71, 26],
 [4, -13, 55, 34, 15]]

Output:
[
[12],
[7, 45],
[21, -2, -3],
[31, 14, 15, 4],
[11, 27, 36, -13],
[19, 71, 55],
[26, 34],
[15]
]

Example 2:

Input:
[[1, 2, 3],
 [4, 5, 6],
 [7, 8, 9]]

Output:
[
[1],
[2, 4],
[3, 5, 7],
[6, 8],
[9]
]

Similar questions:

Comments (20)