Math & Geometry: In-place matrix geometry and numeric reasoning
Goal: Learn the pattern first, then apply it to the 8 roadmap problems in this chapter.
When this pattern appears
A transformation has a geometric symmetry, digit arithmetic, or repeated numeric state.
The reusable idea
Derive coordinates or carry transitions on a small example before coding.
A deliberate problem-solving routine
- Write the input and output in plain language. Identify whether order, duplicates, or mutation matter.
- Work a tiny example by hand; label the state you wish you had at each step.
- Choose the structure or invariant that stores that state.
- Establish a brute-force baseline, then show exactly which repeated work the pattern removes.
- State the invariant before the loop, after each iteration, and at termination.
- Test smallest, boundary, duplicate, and adversarial cases.
Watch the animated pattern
The diagram above this lesson animates the core state changes for this chapter. Use pause and step to predict what moves next. The same invariant should explain each application, even when the problem story changes.
Questions to ask yourself
Can the transformation be decomposed into simpler operations with a clear invariant?
Common failure modes
Rectangular versus square dimensions, mutation order, overflow, and zero handling.
Chapter problems from the workbook
- #136 · Rotate Image — Day 81, Medium. Open problem ↗
- #137 · Spiral Matrix — Day 81, Medium. Open problem ↗
- #138 · Set Matrix Zeroes — Day 82, Medium. Open problem ↗
- #139 · Happy Number — Day 82, Easy. Open problem ↗
- #140 · Plus One — Day 83, Easy. Open problem ↗
- #141 · Pow(x, n) — Day 83, Medium. Open problem ↗
- #142 · Multiply Strings — Day 85, Medium. Open problem ↗
- #143 · Detect Squares — Day 85, Medium. Open problem ↗
Interview explanation
A concise explanation has four parts: the key observation, the maintained invariant, why each step preserves it, and the time/space complexity. Avoid naming a pattern as a substitute for proving the step is safe.