498 Diagonal Traverse
Last updated
Last updated
Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image.
Example:
Note: The total number of elements of the given matrix will not exceed 10,000.
The Idea: First grab the elements that make the 'L' as shown below. Then take the diagonal of each element. Reverse the diagonal as you go for each alternative diagonal.
Complexity: O(n) time and O(1) space