You are given a grid of numbers matrix with m rows and n columns. Start at the top-left corner and walk along the edge of the grid in a spiral: first to the right, then down, then to the left, then up, and keep turning clockwise into the centre.
Return all the numbers in the order you meet them.
Examples
Example 1:
Input: matrix = [[2,4],[6,8]]
Output: [2,4,8,6]
Explanation: Right: 2, 4. Down: 8. Left: 6.
Example 2:
Input: matrix = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
Output: [1,2,3,6,9,12,11,10,7,4,5,8]
Explanation: The walk goes around the outside and then ends in the middle with 5 and 8.
Example 3:
Input: matrix = [[4],[5],[6],[7]]
Output: [4,5,6,7]
Explanation: One column, so we only go down.