Loading...
Given an m x n integer matrix, return all of its values in clockwise spiral order: walk the top row left to right, then the right column downward, then the bottom row right to left, then the left column upward, then repeat on the rectangle that remains inside, until every value has been visited exactly once.
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,3,6,9,8,7,4,5]
Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
Output: [1,2,3,4,8,12,11,10,9,5,6,7]
m == matrix.length, n == matrix[i].lengthmatrix[i][j] ≤100Click "Run" to test with sample cases or "Submit" to run all tests.