54. Spiral Matrix

Medium — Matrix Simulation

Layer by Layer
Direction Vectors
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)