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.

  1. Use the sum row + col (from 0 to (rows + cols - 2)).
  2. For even sums, go up-right. For odd sums, go down-left.
  3. Print every element in order on a new line.

01EXAMPLE 1

Input[[1,2],[3,4]]
Output1 2 3 4

Explanation: Path: 1 -> 2 -> 3 -> 4.

Constraints

  • Handle rectangular matrices.
MatrixLogic
JavaScript
Loading...
1 Hidden

Input Arguments

mat[[1,2],[3,4]]

Expected Output

1
2
3
4

Click RUN to test your solution