54. Spiral Matrix
Medium — Matrix Simulation
Layer by Layer
Direction Vectors
Rows:
1
2
3
4
5
6
Cols:
1
2
3
4
5
6
Apply
Generate
Play
Pause
Step
Reset
Speed:
Slow
Normal
Fast
Very Fast
Press "Play" or "Step" to walk through the spiral.
Step
0 / 0
Visited
0
Direction
→
Output Length
0
Current cell
Next cell
Active band
Already emitted
Algorithm Complexity (smaller bar = faster / less memory)
Direction + Visited
O(mn) / O(mn)
Time / Space: O(mn) / O(mn)
Layer by Layer
O(mn) / O(1)
Time / Space: O(mn) / O(1)
In-Place Marker
O(mn) mutates
Time / Space: O(mn) / O(1)