← Matrix Traversal

Pattern Recognition Drill

#117 — Rotate Image

Medium Math & Geometry

The Problem

Rotate an n×n matrix 90 degrees clockwise in-place.

What approach would you use?

Think about it before scrolling down.

Key Signals

Matrix Traversal

Transpose (swap m[i][j] with m[j][i]), then reverse each row. O(n²).

Alt: Math / Number Theory

Rotate four cells at a time in concentric rings. Same O(n²) but trickier.

Common Trap

Transpose + reverse rows = 90° CW. Transpose + reverse columns = 90° CCW. Don't mix them up.

← #116