dsa · medium
Spiral Matrix
GreyOrangeArray
Return the spiral order of matrix (right, down, left, up).
Arguments
matrix— the 2D grid / matrix
**Example:** [[1,2,3],[4,5,6],[7,8,9]] → [1,2,3,6,9,8,7,4,5].
Constraints
1 <= m, n <= 10 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [[1,2,3],[4,5,6],[7,8,9]] Expected: [1,2,3,6,9,8,7,4,5]