Rotate matrix 90 degrees
Your task
Given an n x n 2D matrix representing an image, rotate it 90 degrees CLOCKWISE in place (modify and return the same matrix; do not allocate another n x n grid). For example the top row becomes the right column. n is up to 1000. The clean approach is transpose-then-reverse-each-row, both done in place.
Examples
rotate_image(matrix: list[list[int]]) -> list[list[int]]Example 1
Input
rotate_image([[1, 2, 3], [4, 5, 6], [7, 8, 9]])Output
[[7, 4, 1], [8, 5, 2], [9, 6, 3]]