Diagonal Traverse
HardAcc. 78.5%
+45 XP 20
Vector Zig-Zag
Elements on the same diagonal have the same sum: row + col = constant.
The Assignment
Your function receives mat.
- Use the sum
row + col(from 0 to (rows + cols - 2)). - For even sums, go up-right. For odd sums, go down-left.
- Print every element in order on a new line.
01EXAMPLE 1
Input
[[1,2],[3,4]]Output
1
2
3
4Explanation: Path: 1 -> 2 -> 3 -> 4.
Constraints
- Handle rectangular matrices.
MatrixLogic
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
mat[[1,2],[3,4]]
Expected Output
1 2 3 4
Click RUN to test your solution