S
All challenges
Practice
Home
Blog
Practice
Examples
Feedback
Spiral Matrix Traversal
00:00
Start
00:00
Sign in
Problem
Hints
3
Solution
History
Medium
Array
Matrix
Simulation
Amazon
Microsoft
Adobe
Return all elements of an m×n matrix in spiral order (clockwise from top-left).
Examples
Example 1
Input →
[[1,2,3],[4,5,6],[7,8,9]]
Output →
[1,2,3,6,9,8,7,4,5]
Example 2
Input →
[[1,2,3,4],[5,6,7,8],[9,10,11,12]]
Output →
[1,2,3,4,8,12,11,10,9,5,6,7]
JavaScript
Python
Java (Coming soon)
C (Coming soon)
C++ (Coming soon)
Reset
Run
Submit
Cases
Results