Rotate Image
Rotate an n × n matrix 90° clockwise, in place.
A way to picture it
Turning a photo a quarter-turn by hand is fiddly. Two easy moves do the same thing: flip the photo over its diagonal (like folding it corner to corner), then look at it in a mirror.
How to approach it
Transpose (swap matrix[i][j] with matrix[j][i]), then reverse each row. Together they make a clockwise quarter-turn.
Example
Input: {"matrix":[[1,2,3],[4,5,6],[7,8,9]]}. Output: [[7,4,1],[8,5,2],[9,6,3]].
Complexity: O(n²) time and O(1) space. Every cell is swapped a constant number of times, in place.
This page includes an animated walkthrough, Java and Python solutions, and a question to check your understanding.