2D Matrix & Grid Traversal/Medium

Rotate ImagePRO PASS

Time: O(N²)Space: O(1)

Step 1: Setup & Initialization - Rotate Image

Transpose matrix elements along diagonal, then reverse each row.

Array Elements & Pointers
10
[0]
20
[1]
30
[2]
40
[3]
50
[4]
Live Variables & Invariants
status:Initialized
pattern:Rotate Image
Step 1 / 333%
Solution Code
1
function rotate(matrix: number[][]): void {
2
  const n = matrix.length;
3
  for (let r = 0; r < n; r++)
4
    for (let c = r; c < n; c++) [matrix[r][c], matrix[c][r]] = [matrix[c][r], matrix[r][c]];
5
  for (let r = 0; r < n; r++) matrix[r].reverse();
6
}

Custom Test Case Runner

Input your custom values and visualize step-by-step trace

Quick Presets:

AI DSA Coach

Contextual Tutor for Rotate Image

Hello! I am your AI DSA Tutor for **Rotate Image** (2D Matrix & Grid Traversal). Ask me anything about this algorithm, time complexity, or request a step hint!