dsa · medium

Rotate Image

You are given an n × n matrix. Rotate it **90 degrees clockwise in place** and return the matrix.

Arguments

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]]

Open in the Dojo editor