Skip to the workspace
Pebellslearn by building
Backtracking  ›  Capstone Project

Capstone: Which Pattern Is This?

More Exercises 18 minBefore coding, climb a short ladder of signals (list every option, a contiguous stretch, sorted data, the smallest value that works, a lookup) and check the chosen pattern against the input limits.

leetcode / Capstone: Which Pattern Is This?

Explore each scene at your own pace.

01 · The rule

The rule

Capstone: Which Pattern Is This?

You now own a small toolbox: seen-sets, complement lookups, counting, canonical keys, prefix sums, two pointers, binary search on lists and on answers, fixed and variable windows, and backtracking. In an interview nobody tells you which tool the problem wants. This final lesson is the habit that picks one in the first minute, before any code exists.

The rule

Name the pattern before you write a single line of code.

The first lesson of this course gave three questions. With everything since, they grow into a recognition ladder. Climb it from the top and stop at the first rung that fits:

Rung Signal Reach for
1 "list every", "all ways", tiny limits backtracking: subsets, orderings or pruned combinations
2 "contiguous", "stretch", "substring" sliding window, or prefix sums if values can be negative or ranges are asked many times
3 sorted data, pairs or triples, "both ends" two pointers, or binary search to locate a value or a boundary
4 "the smallest (or largest) x that still works" binary search on the answer, with a yes-no checker
5 "seen before", "partner", "how many of each", "group" set, dictionary, counts or canonical keys

Then check the fit against the limits, as in the very first lesson. A pattern that is too slow for the largest input, or that needs sorted data you are not allowed to sort, is the wrong rung: climb on.

Two habits make the ladder reliable. Say why the tempting rung fails, not just why the chosen one fits: "not a window, because values can be negative" is exactly the reasoning interviewers hope to hear. And remember that patterns combine: a window that keeps a dictionary of counts, prefix sums that lean on a complement lookup, binary search whose checker is a greedy pass.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.