#498
Diagonal Traverse
specialist · 620 · lc medium +29 · verified · 67% accepted · 4,303 likes · top 73%
Description
Given an m x n matrix mat, traverse all elements in diagonal order and return them as a flat array. Diagonals alternate between going up-right and down-left.
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]
Code
1
2
3