DIY: Rotate Image
Solve the interview question "Rotate Image" in this lesson.
We'll cover the following
Problem statement
For this problem, you are given a 2D array. You have to implement the function that will rotate the image pixels given in a matrix form clockwise.
Constraints
len(matrix) == n
len(matrix[i]) == n
- 1 <=
n
<= 20 - -1000 <=
matrix[i][j]
<= 1000
Input
The input of the autoRotate()
function is a 2D array. Here is an example of the input:
[[1,2,3],[4,5,6],[7,8,9]]
Output
This is the output of the input given above:
[[7,4,1],[8,5,2],[9,6,3]]
Coding exercise
Implement the autoRotate(matrix)
function, where the matrix
represents a 2D array and returns the matrix.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.