Diagonal Traverse
Solution ApproachWas this helpful?
Medium•array•Expected: O(n×m) time, Unknown space
Problem
Given an m x n matrix, return all elements in diagonal order.
Example 1:
Input: mat = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Output: [1, 2, 4, 7, 5, 3, 6, 8, 9]
Example 2:
Input: mat = [[1, 2],
[3, 4]]
Output: [1, 2, 3, 4]
Reference solution unlocks after your first submission
Loading...
