dsa · medium
Rotate Image
You are given an n × n matrix. Rotate it **90 degrees clockwise in place** and return the matrix.
Arguments
matrix— n by n grid of integers; rotate it clockwise and return it
Example
[[1,2,3],[4,5,6],[7,8,9]] → [[7,4,1],[8,5,2],[9,6,3]].
The first row becomes the last column.
Constraints
1 <= n <= 20 matrix.length == n matrix[i].length == n Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [[1,2,3],[4,5,6],[7,8,9]] Expected: [[7,4,1],[8,5,2],[9,6,3]]
Example 2
Input: [[1,2],[3,4]] Expected: [[3,1],[4,2]]