Rotate Image
Part of Practice: Matrix Choreography
You are given an n x n grid of numbers representing an image. Rotate the image 90 degrees clockwise, modifying the grid in place — you may not allocate a second matrix and copy into it.
Constraints that matter: the matrix is square (rotation would change the shape otherwise) and n is at most 20, so the challenge is purely about doing the swap dance correctly, not about speed.
Examples
- Input:
- matrix = [[1,2,3],[4,5,6],[7,8,9]]
- Output:
- [[7,4,1],[8,5,2],[9,6,3]]
The left column (1,4,7) read bottom-to-top becomes the top row (7,4,1), and so on for each column.
- Input:
- matrix = [[5,1],[2,4]]
- Output:
- [[2,5],[4,1]]
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.