synopsis · Thinking tools · chapter 6

Mindset & Problem Solving

9 cards, about a minute. Read them the night before an interview, or right after the chapter to lock it in.

  1. what it is

    A routine, not genius: Understand → Match → Plan → Implement → Review → Evaluate. Same steps every time, so you always know the next one.

  2. use it when

    Every coding round and every practice problem — and the moment you freeze. Next step is always: restate it, then solve one tiny example by hand.

  3. template

    Say it out loud: "Brute force is O(n²) because… The repeated work is… A HashMap makes that O(1), so O(n) time, O(n) space."

  4. cost

    Constraints pick the idea: n ≤ 20 → 2ⁿ · n ≤ ~5,000 → n² (10⁴ borderline) · n ≤ 10⁵–10⁶ → n log n or n. Budget ≈ 10⁸ simple steps per second.

  5. trap

    Coding before understanding. Most wrong answers solve a slightly different problem. Restate it and run one example by hand first.

  6. trap

    int stops at 2,147,483,647. Products like 10⁵ × 10⁵ or sums of many big values need long — cast before the operation.

  7. pro tip

    Dry run with a table (one row per iteration, one column per variable), then test: empty, one element, duplicates, negatives, max values.

  8. pro tip

    Practice: stuck 20 minutes → read one hint. Re-solve from a blank page after 1, 3, 7, 16 and 35 days.

  9. pro tip

    At home, stress test: compare your fast code with the brute force on thousands of tiny random inputs (fixed seed).

Shaky on a card? Open the chapter or flip its recall cards.