Pattern 17 of 18 · Final Stretch

Math & Geometry

Number theory, simulation, and coordinate geometry that show up in unexpected places.

A grab-bag of problems solved with numeric or coordinate reasoning rather than a specific data structure — matrix manipulation, simulation, and basic number theory.

Key concepts

  • In-place matrix operations: rotate, transpose, or zero out parts of a matrix without allocating a second matrix.
  • Simulation: directly model what the problem describes (walking in a spiral, moving in a direction) rather than finding a shortcut formula.
  • Basic number theory: divisibility, modular arithmetic, and bit-level tricks for integer problems.

When to use it

  • The problem operates on a 2-D grid or matrix directly (rotate, transpose, traverse in a pattern).
  • There's no obvious "textbook" data structure — the problem is really about careful step-by-step simulation.

Tips

  • For in-place matrix rotation, transpose-then-reverse (or vice versa) is a reliable trick worth memorizing.
  • When simulating movement (like a spiral), track shrinking boundaries (top/bottom/left/right) rather than recomputing bounds each step.
  • Watch for integer overflow and off-by-one errors — they're the most common bugs in this category.

Practice problems (8)

Blind 75 (3):

More from Blind 150 (5):

See the full roadmap →