Skip to interview prep
Apexed

77. Rotate a Matrix 90°

MediumMiscellaneous

Rotate an n × n matrix 90° clockwise in place and return it.

Example 1

Input: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Output: [[7, 4, 1], [8, 5, 2], [9, 6, 3]]

Constraints

  • 1 ≤ n ≤ 20

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 3 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Rotate a Matrix 90° — coding interview practice — Apexed