Pattern Recognition Drill
Medium Math & Geometry
The Problem
Rotate an n×n matrix 90 degrees clockwise in-place.
What approach would you use?
Think about it before scrolling down.
Transpose (swap m[i][j] with m[j][i]), then reverse each row. O(n²).
Rotate four cells at a time in concentric rings. Same O(n²) but trickier.
Common Trap
Transpose + reverse rows = 90° CW. Transpose + reverse columns = 90° CCW. Don't mix them up.