Problem
You get a square matrix matrix with n rows and n columns. A matrix is a grid of numbers. Rotate the matrix by 90 degrees in the clockwise direction.
Rotate the matrix in place. In place means that you change the given matrix and do not make a second matrix. The function returns nothing.
Example 1
- Input:
- matrix = [[1,2],[3,4]]
- Output:
- [[3,1],[4,2]]
- Explanation:
- The first column, read from bottom to top, becomes the first row.
Example 2
- Input:
- matrix = [[7,0,5],[2,9,1],[6,3,8]]
- Output:
- [[6,2,7],[3,9,0],[8,1,5]]
- Explanation:
- The center item stays in its position. Each corner item moves to the next corner in the clockwise direction.
Constraints
- n == matrix.length == matrix[i].length
- 1 <= n <= 20
- -1000 <= matrix[i][j] <= 1000
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Rotate Array
Coding · Array · Math · Two Pointers
- Candy Crush
Coding · Array · Matrix · Simulation
- Construct Quad Tree
Coding · Array · Divide and Conquer · Matrix
- Contain Virus
Coding · Array · Breadth-First Search · Depth-First Search
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
Meta
Leetcode 48. Rotate Image
Reported Feb 14, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 3 records
Bloomberg
Rotate Image
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 64.8. This is not an interview probability.
View sourceByteDance
Rotate Image
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 88.4. This is not an interview probability.
View sourceNVIDIA
Rotate Image
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026