LeetCode 48 ·
Medium
Rotate Image
Rotate an n×n matrix 90° clockwise in place.
Try it
Step through the core mechanic. The simulator below runs the math shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is Math — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
Transpose the matrix (swap across the diagonal), then reverse each row. The two reflections compose into a 90° rotation, all in O(1) extra space.
| Aspect | Value |
|---|---|
| Pattern | Math |
| Recognise it by | Rotate a matrix 90° in place. |
| Time complexity | O(n²) |
| Space complexity | O(1) |
| Difficulty | Medium |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.