Rotate Image

Try to solve the Rotate Image problem.


Given an n×nn \times n matrix, rotate the matrix 90 degrees clockwise. The performed rotation should be in place, i.e., the given matrix is modified directly without allocating another matrix.

Note: The function should only return the modified input matrix.


  • matrix.length == matrix[i].length
  • 11 \leq matrix.length 20\leq 20
  • 103-10^3 \leq matrix[i][j] 103\leq 10^3


Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy