The input is an m x n matrix. Return all of its elements in spiral order, starting from the top-left corner. Amazon uses matrix traversal problems to test boundary tracking and direction logic.
For example, given [[1,2,3],[4,5,6],[7,8,9]], you return [1,2,3,6,9,8,7,4,5]. You move right across the top, down the right side, left across the bottom, up the left side, and then repeat inward.
Constraints: both m and n are between and . Think about how you'd define the boundaries of the spiral and shrink them after each pass.