You're given an m x n matrix. Return all elements in diagonal order, alternating direction on each diagonal. Meta asks matrix traversal problems to test your ability to handle direction changes and boundary logic.
For example, given [[1,2,3],[4,5,6],[7,8,9]], the output is [1,2,4,7,5,3,6,8,9]. The first diagonal goes up-right, the next down-left, and so on.
The tricky part is handling boundary conditions when a diagonal hits an edge. What do you do when you can't keep going in the current direction?
Constraints: , .