Rotate Image
Recognize the pattern
Brute force idea
A straightforward first read of Rotate Image is this: Create new matrix, copy rotated positions. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
Better approach
The real unlock in Rotate Image comes when you notice this: Transpose the matrix (swap rows and columns), then reverse each row. Or rotate layer by layer with four-way swaps. Instead of recomputing the world every time, you preserve just enough context to let the next decision become obvious.
Key invariant
The compass for Rotate Image is this: 90° clockwise rotation = transpose (swap matrix[i][j] with matrix[j][i]) followed by horizontal flip (reverse each row). These two operations compose to produce the rotation. As long as that statement keeps holding, you can trust the steps built on top of it.
Watch out for
One easy way to drift off course in Rotate Image is this: Transposing the full matrix instead of just the upper triangle — swapping (i,j) and (j,i) twice puts them back. Only swap when i < j. The fix is usually to return to the meaning of each move, not just the steps themselves.