Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Spiral Matrix
Bookmark
Simulation with Direction Arrays
Layer-by-Layer
Input
3×3 Matrix
3×4 Matrix
2×2 Matrix
4×5 Matrix
Single Row
Single Column
Custom
matrix
=
[[1,2,3],[4,5,6],[7,8,9]]
MATRIX
1
2
3
4
5
6
7
8
9
RESULT
MATRIX
1
2
3
4
5
6
7
8
9
RESULT
MATRIX
→ right
1
2
3
4
5
6
7
8
9
RESULT
1
MATRIX
→ right
1
2
3
4
5
6
7
8
9
RESULT
1
2
MATRIX
↓ down
1
2
3
4
5
6
7
8
9
RESULT
1
2
3
MATRIX
↓ down
1
2
3
4
5
6
7
8
9
RESULT
1
2
3
6
MATRIX
← left
1
2
3
4
5
6
7
8
9
RESULT
1
2
3
6
9
MATRIX
← left
1
2
3
4
5
6
7
8
9
RESULT
1
2
3
6
9
8
MATRIX
↑ up
1
2
3
4
5
6
7
8
9
RESULT
1
2
3
6
9
8
7
MATRIX
→ right
1
2
3
4
5
6
7
8
9
RESULT
1
2
3
6
9
8
7
4
MATRIX
1
2
3
4
5
6
7
8
9
RESULT
1
2
3
6
9
8
7
4
5
algo
master
.
io
Step:
Start: Traverse the matrix in spiral order by simulating the walk
0 / 31
Input
3×3 Matrix
3×4 Matrix
2×2 Matrix
4×5 Matrix
Single Row
Single Column
Custom
matrix
=
[[1,2,3],[4,5,6],[7,8,9]]
0 / 31
algo
master
.
io
Step:
Start: Traverse the matrix in spiral order by simulating the walk