Given an m x n matrix of integers, return all elements ordered by diagonal.
Diagonals are defined by the sum row + col. Elements with the same row + col value belong to the same diagonal. Start from diagonal 0 (top-left corner) and proceed to the last diagonal.
Within each diagonal, elements are ordered from top to bottom (i.e., by increasing row index).
For example, in a 3x3 matrix:
matrix = [[1,2,3],[4,5,6],[7,8,9]][1, 2, 4, 3, 5, 7, 6, 8, 9]matrix = [[1,2],[3,4],[5,6]][1, 2, 3, 4, 5, 6]1 <= m, n <= 100-10^4 <= matrix[i][j] <= 10^4The matrix is non-emptyRun your code to see results
Use Cmd+Enter to run