Given an m×n matrix, return an array containing the matrix elements in spiral order, starting from the top-left cell.
Constraints:
- 1≤
matrix.length ≤10
- 1≤
matrix[i].length ≤10
- −100≤
matrix[i][j] ≤100
The essence of the spiral order traversal algorithm for matrices lies in navigating through the matrix in a spiral pattern—initially moving left-to-right, then top-to-bottom, followed by right-to-left, and finally bottom-to-top, with this cycle repeating until all elements have been visited. ...