← All problems
Spiral Matrix
Given an m x n matrix, return all its elements in spiral order, starting at the top-left and moving clockwise inward.
Complexity
Time O(mn), Space O(1) excluding output
Common pitfalls
- Double-visiting the last row/column
- Off-by-one on boundaries
Your solution
Log in to save your code and track progress.