Matrices
Medium

Rotate Image

Rotate the matrix by 90 degrees clockwise in-place.
Problem Understanding

You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place.

Strategy (Transpose + Reflect)
  1. Transpose: Swap matrix[i][j] with matrix[j][i].
  2. Reflect: Reverse each row.
  • Step 1: Transpose converts rows to columns.

  • Step 2: Reversing rows fixes the left-right order for 90 deg rotation.

Interactive Visualization
Step 1 / 1

Visualization data missing

Initializing...

1x
See the Logic in Motion
Stop memorizing code. Unlock the full interactive visualizer to master the logic step-by-step.
Unlock VisualizerPREMIUM FEATURE

Stop Guessing, Start Mastering.

Build the FAANG intuition. Master this pattern with optimized implementations, visual dry runs, and our curated collection of high-yield problems.

Start Your Premium Prep