Array / Matrix•Pattern: Matrix Manipulation•Medium

Rotate an n×n matrix in-place by 90°

Problem Intuition & Objective

Rotate a square matrix 90° clockwise without using extra space.

Time ComplexityO(n²)
Optimal
Space ComplexityO(1)
Memory Bounds
Optimal Algorithmic Approach

Transpose + Row-Reverse. Both steps are O(n²) and in-place.

Core Invariants & Edge Cases

  • Step 1: Transpose the matrix (swap matrix[i][j] with matrix[j][i])
  • Step 2: Reverse each row
  • These two steps compose to a 90° clockwise rotation
Previous ProblemSpiral order traversal of a matrixNext Problem Subarray sum equals K

System Design & Architecture Roadmap

Coding interviews are only 50% of the bar. Master High-Level Design, distributed systems, and Object-Oriented LLD.