Back to course home
0% completed
Vote For New Content
Diagonal Traverse (medium)
Problem Statement
Given a 2D matrix of size m x n
, return a 1D array containing elements of the matrix in the diagonal order.
Example 1:
- Input: `matrix =
[[1,2,3],
[4,5,6]]
- Expected Output:
[1,2,4,5,3,6]
- Justification: Traversal begins at 1, moves to 2, diagonally down to 4, up to 5, down to 3, and finally to 6.
Example 2:
- Input: matrix =
[[1,5],
[3,6]]
- Expected Output:
[1,5,3,6]
- Justification: The traversal starts from 1, moves to 2, then down to 3, and finally to 4.
Example 3:
- Input: `matrix =
[[1],
[2],
[3]]
- Expected Output:
[1,2,3]
- Justification: The traversal is straightforward down the single-column matrix.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible