Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.
Example 1
Input: mat = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,4,7,5,3,6,8,9]
Explanation: Walk the diagonals in a zigzag: [1] going up, [2,4] going down, [7,5,3] going up, [6,8] going down and [9]. Joining them gives [1,2,4,7,5,3,6,8,9].
Example 2
Input: mat = [[1,2],[3,4]]
Output: [1,2,3,4]
Explanation: The diagonals are [1], then [2,3] read downward, then [4], giving [1,2,3,4].
Example 3
Input: mat = [[1]]
Output: [1]
Explanation: A 1x1 matrix has a single element, so the answer is [1].
Cells on the same diagonal share the sum r + c. Iterate diagonals 0..m+n-2, walking up-right on even diagonals and down-left on odd ones.
Run checks all cases above. Submit evaluates all test cases.