54. Spiral Matrix

Practice Spiral Matrix for free on NudgeCode: Medium, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return all values of the m x n matrix in spiral order: start at the top-left corner, go right along the top row, down the right column, left along the bottom row, up the left column, and keep circling inward until every cell is visited.

Example

matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]  ->  [1,2,3,4,8,12,11,10,9,5,6,7]

Constraints