Rotate Matrix

You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

You need to do this in place.

Note that if you end up using an additional array, you will only receive partial score.

Example:

If the array is

[
    [1, 2],
    [3, 4]
]

Then the rotated array becomes:

[
    [3, 1],
    [4, 2]
]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Rotate Matrix on Interview Code Editor
Sign Up
to access hints and editorial solutions for Rotate Matrix
10123 successful submissions.
Asked In:
  • Google
  • Facebook
  • Amazon
Click here to start solving coding interview questions