Treat the matrix as coordinates. Common tricks: transpose-then-reverse for rotation, layer-by-layer peeling for spiral traversal, row/column flags for zeroing in place.
Sub-patterns
- A — Rotation. Transpose-then-reverse to rotate in place.
- B — Spiral Traversal. Layer-by-layer peeling from the outside in.
- C — Search in a Sorted Matrix. Exploit row- and column-sorted order.
- D — In-Place Marking. Row/column flags to mark cells without extra space.
Practice set (5)
- Medium — Rotate Image, Spiral Matrix, Set Matrix Zeroes, Search a 2D Matrix II, Game of Life
Pending
Rotation
Transpose-then-reverse to rotate a matrix in place.
Pending
Spiral Traversal
Layer-by-layer peeling from the outside in.
Pending
Search in a Sorted Matrix
Exploit row- and column-sorted order to search faster than a full scan.
Pending
In-Place Marking
Use row/column flags to mark cells for later processing without extra space.
Notes from readers
Comments — via GitHub