Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rotate Square Matrix In Place

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Rotate Square Matrix In Place. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an n x n matrix of integers represented as a list of lists, rotate the matrix 90 degrees clockwise in place. Modify the input matrix directly and return it. You may not allocate another n x n matrix for the result.

Constraints

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

Function Signature

def rotate_matrix(matrix):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output