Spiral Matrix
Return matrix entries in clockwise spiral order, beginning at the top-left and first moving right.
Example 1
0,01
0,12
0,23
1,04
1,15
1,26
matrix = [[1,2,3],[4,5,6]][1,2,3,6,5,4]Explanation
Read top row 1,2,3, right edge 6, then bottom row backwards 5,4.
Example 2
0,01
1,02
2,03
matrix = [[1],[2],[3]][1,2,3]Explanation
Read the single column downwards without revisiting cells.
Example 3
0,07
matrix = [[7]][7]Explanation
The only cell is emitted once.
Constraints
- 1 <= rows,columns <= 10
- Entries are signed integers
Function contract
spiralOrderArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[1,2,3],[4,5,6]]