Practice Diagonal Traverse
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.
Source: Diagonal Traverse on LeetCode. Use the original task for its coding environment and submissions.
Examples
# 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]
Constraints
m == mat.length
n == mat[i].length
1 <= m, n <= 10^4
1 <= m * n <= 10^4
-10^5 <= mat[i][j] <= 10^5
Related LeetCode Problems
Practice more problems similar to Diagonal Traverse.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.