Rotate Image

You are given an n x n grid of numbers. Rotate it 90 degrees clockwise, so the first row ends up as the last column, the second row as the second-to-last column, and so on.

You must do this in place: change the grid you were given, and do not create a second grid. The function returns nothing; the tests inspect the grid after it returns.

Constraints

  • 1 <= n <= 20
  • -1000 <= matrix[i][j] <= 1000

Examples

Example 1

Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [[7,4,1],[8,5,2],[9,6,3]]

The first row 1 2 3 becomes the last column, read top to bottom. The test checks the matrix after your function returns.

Example 2

Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]

The same idea on a 4 x 4 grid: the bottom-left corner 15 moves to the top-left.

Example 3

Input: matrix = [[1]]
Output: [[1]]

JavaScript you'll use: Arrays: create, read, update Destructuring, spread and rest

/**
 * @param {number[][]} matrix
 * @return {void}
 */
function rotate(matrix) {
  
}

Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.