A Repeatable Approach to New Problems

Follow a fixed routine for unseen problems: understand, find examples, brute force, map to a pattern, optimise, code, then test edge cases.

Beginner · about 3 hours · difficulty 2/5

Learn first: Prefix Sums and Difference Arrays

The goal of practice is not to memorise 500 solutions. It is to reliably solve a problem you have never seen. A fixed routine makes that possible under pressure.

The routine

  1. Restate the problem and confirm input sizes, value ranges and edge cases.
  2. Work two or three examples by hand, including a tricky one.
  3. State a brute force and its complexity, even if it is too slow.
  4. Use the constraints to pick a target complexity, then map to a pattern: sorted input suggests two pointers or binary search; contiguous range suggests sliding window or prefix sums; "all combinations" suggests backtracking; "minimum or maximum ways" with overlapping choices suggests DP; dependencies suggest graphs.
  5. Write the code in small, named pieces.
  6. Dry-run on your examples, then test empty input, single element, duplicates, negatives and maximum sizes.

When you are stuck

Give yourself 20 to 30 minutes on a medium problem. Then read only the hint or the pattern name, try again, and only then read the full solution. Re-solve it from scratch the next day.

Pattern recognition cues

Build a personal cue sheet: "k-th largest means heap", "minimise the maximum means binary search on answer", "next greater means monotonic stack". Add a line every time a problem surprises you.

Pitfalls

  • Jumping into code before you have an approach.
  • Reading the solution after five minutes, which trains recognition, not problem solving.

You are ready to move on when you can talk through steps 1 to 4 aloud on a new medium problem within 10 minutes.

Key concepts

  • Clarifying constraints and edge cases
  • Brute force first
  • Constraint-driven pattern choice
  • Dry runs and test cases
  • The 20-30 minute stuck rule
  • Personal pattern cue sheet

Mini project

Pick 6 unseen medium problems from mixed topics. For each, write the six routine steps in a notebook before coding, time each step, and note which cue led you to the pattern.

Check yourself

A problem asks for the minimum possible largest sum when splitting an array into k parts with n up to 1e5. Which pattern do the words and constraints point to?

Free resources