Back to questions

Clock-wise Matrix Rotation Adobe Python Interview Question

Clock-wise Matrix Rotation

Adobe Python Interview Question

You are given an n x n 2D matrix representing an image, and you need to rotate the image by 90 degrees clockwise. You are basically being asked to implement the functionality of numpy.rot90(matrix, k=-1) (without actually using any helper functions or outside libraries).

Example #1

Input: matrix =

Output:

Example #2

Input: matrix =

Output:

Bonus Challenge: In-Place Rotation

Implement the rotation in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.

Input

Python

Output