Unit 1 · Algorithms · Lesson 24 of 24
Pattern recognition and mixed practice
Step 1: Learn the ideas
- Signals to candidate patterns
- Applicability conditions and invariants
- Constraints as complexity hints
- Stateful data-structure design
- Combining patterns
- Mixed (interleaved) practice
- Spaced review through new problems
- Practice logs and weakness tracking
- Using LeetCode 75 and Top Interview 150 as pools
Why it matters
Interview problems come from a large space, and you will rarely meet one you have practiced. What transfers is the ability to read a statement, notice its signals and test a few candidate techniques against their preconditions. Memorizing solutions, or lists of questions said to be used by particular companies, does not build that ability and fails as soon as a problem is altered. Learning research also generally favors interleaved practice and spaced review over blocked repetition: mixing problem types forces you to choose the technique, which is precisely the skill being tested.
Core ideas
Signals, candidates, conditions. Read the constraints and the question, map them to a short list of candidates, and check each candidate's condition before committing.
| Signal | Candidate patterns | Condition or invariant to check |
|---|---|---|
| Complement lookup, duplicates, grouping | hashing, frequency counting | Equal keys identify equivalent items |
| Pairs in sorted input, in-place partitioning | two pointers | Each move discards candidates that cannot improve the answer |
| Contiguous subarray or substring | sliding window, prefix sums | Window validity is monotone (often needs non-negative values); otherwise prefix sums with a hash map |
| Sorted input, or smallest feasible value | binary search, binary search on the answer | A predicate that flips from false to true exactly once |
| Overlapping ranges, many range updates | sorting, interval merging, sweep line | Sort key matches the objective |
| Nested structure, matching, undo | stack | Top is the most recent unresolved item |
| Next greater or smaller, window extremes | monotonic stack or deque | Stored indices stay in monotone order |
| k largest, running median, merging streams | heap selection, two heaps | Heap top is the current extreme; size stays bounded |
| Reordering a list, cycles, middles | linked-list pointers, fast and slow pointers | Save next before rewiring; fast moves twice as far |
| Hierarchy, subtree answers | tree DFS or BFS, BST invariant | Each subtree returns a summary its parent can combine |
| Many prefix queries over words | trie | Each node represents one prefix |
| Minimum steps, grids, transformations | graph BFS or DFS, grid as implicit graph, multi-source BFS | Unit weights; mark visited on enqueue |
| Prerequisites, dependencies | topological ordering, cycle detection | An order exists only for a DAG |
| Groups merging over time | union-find | Undirected, unions only |
| Cheapest weighted route | shortest paths | Weight sign decides Dijkstra or Bellman-Ford |
| All combinations or placements | backtracking | Choose, recurse, undo; prune early |
| Count ways, best total over choices | DP (1D, grid, strings, knapsack) | Overlapping subproblems with a valid evaluation order |
| A locally best choice looks safe | greedy | An exchange argument exists |
| Independent halves, k-th order statistic | divide and conquer | Subproblems do not overlap; write the recurrence |
| Parity, small sets encoded as masks | bit manipulation | Width and signedness are explicit |
| Fast operations on changing data | stateful design | Map plus list, heap or sorted structure kept consistent |
Constraints narrow the list: n up to about 20 allows exponential search, n around 10^3 allows O(n^2), and n around 10^5 or more needs O(n log n) or better.
Mixed practice routine. Once several topics are studied, stop practicing only by topic. A session is three unseen problems from different patterns, 25 to 35 minutes each, with the pattern unknown in advance; the official LeetCode 75 and Top Interview 150 plans and the extra items in each topic are good pools. Before coding, write the signals you noticed and two candidates with the reason for your choice. Afterwards, log the problem, the pattern, whether you recognized it unaided, the time taken and the bug class.
Review rotation. Revisit each pattern at growing intervals, for example after about 2, 7 and 21 days, through a different problem each time. If you learned sliding windows on Longest Substring Without Repeating Characters, review with Permutation in String, then Minimum Window Substring; for BFS, follow Number of Islands with Rotting Oranges, then 01 Matrix. Re-solving the same problem mostly tests memory of that answer. Patterns you recognized late or solved with bugs come back sooner.
Stateful design problems. LRU Cache, Time Based Key-Value Store, Snapshot Array and LFU Cache combine patterns: a hash map for direct access plus a linked list, heap or sorted list for order. State the invariant that links the structures and the cost of every operation.
Common misconceptions
- "The strategy is to memorize the questions a company uses." Such lists cannot be verified, and you will rarely see the same problem; recognition and clean execution transfer.
- "More problems solved means more progress." Many problems practiced by topic, always knowing the pattern beforehand, build less recognition than fewer problems practiced mixed.
- "Review means re-solving the same problem." That rehearses one answer; review the pattern through a new problem.
- "A signal determines the pattern." Signals suggest candidates; the applicability condition decides.
How to approach it
Start mixed practice once arrays and hashing, two pointers, trees, graph traversal and basic DP are studied, and run two or three mixed sessions per week alongside topic study. When a pattern fails repeatedly, return to its topic notes instead of grinding more problems of the same kind. Mid and senior loops typically add design-flavored problems and follow-up extensions, so keep stateful design in the rotation.
Suggested order
- 1For each row of the signals table, write the pattern’s invariant from memory; any you cannot state send you back to that topic first.
- 2Open the LeetCode 75 plan and, without solving, classify ten problems by signal and candidate pattern; check your guesses when you later solve them.
- 3Solve the stateful design set in order: LRU Cache, Insert Delete GetRandom O(1), Time Based Key-Value Store, then Snapshot Array, writing the invariant that links the structures for each.
- 4Start a practice log (problem, signals, pattern, recognized unaided or not, time, bug class) and run a first mixed session of three unseen problems from different patterns.
- 5Schedule reviews: each pattern returns after about 2, 7 and 21 days through a new problem from the topic’s extra items or the Top Interview 150 plan.
- 6Every two weeks, read the log, pick the two weakest patterns and re-study their topic notes before adding problems; use Design Twitter and LFU Cache as harder design reviews.
Step 2: Check off what you can do
Tap each one you can genuinely do or explain. Each earns 10 XP.
Step 3: Go deeper
LeetCode 75 study planStart here
LeetCodeCompact official problem pool for a first mixed pass across the core patterns, used without looking at the section labels first.
Open(opens in a new tab)Not checkable automatically, 5 Oct 2026LeetCode Top Interview 150 study planStart here
LeetCodeLarger official pool with several problems per pattern, which makes it the main source of new problems for the review rotation.
Open(opens in a new tab)Not checkable automatically, 5 Oct 2026MIT 6.006 Introduction to Algorithms (Spring 2020)
MIT OpenCourseWareSection: Lecture notes index
Lists every lecture and recitation PDF; the recitation notes are compact refreshers on the reasoning behind a data structure or algorithm when a pattern keeps failing.
Open(opens in a new tab)Link responded, 5 Oct 2026
Step 4: Practice
Use the two official study plans as pools for mixed sessions, not as checklists to finish in order: pick problems whose pattern you do not know in advance and log the signal that led you to the approach. The design problems exercise the stateful-design pattern, which combines several structures. Review every pattern, this one included, through a problem you have not solved before.
- LeetCode 75 (official study plan)LeetCode(opens in a new tab)Not attemptedLeetCode
- Top Interview 150 (official study plan)LeetCode(opens in a new tab)Not attemptedLeetCode
- LRU CacheLeetCode(opens in a new tab)Not attemptedLeetCode
- Insert Delete GetRandom O(1)LeetCode(opens in a new tab)Not attemptedLeetCode
- Time Based Key-Value StoreLeetCode(opens in a new tab)Not attemptedLeetCode
- Snapshot ArrayLeetCode(opens in a new tab)Not attemptedLeetCode
- Design TwitterLeetCode(opens in a new tab)Not attemptedLeetCode
- LFU CacheLeetCode(opens in a new tab)Not attemptedLeetCode
Record attempts on each problem’s page (+15 XP, +10 more when solved on your own).
Step 5: Test yourself
Answer each one out loud or on paper before you finish the lesson.
- Question 1Which signals suggest a sliding window, and what condition makes it valid?
- Question 2When does a minimum-steps problem need Dijkstra instead of BFS?
- Question 3Which signals point to DP rather than greedy, and how would you check?
- Question 4Which patterns did you recognize late in your last mixed session, and why?
- Question 5Why is reviewing a pattern through a new problem more useful than re-solving an old one?
- Question 6What invariant links the hash map and the linked list in an LRU cache?
You’re done when you can
- State the applicability condition and invariant of every pattern in the signals table without notes.
- Complete four mixed sessions of three unseen problems each, recognizing the pattern unaided in at least two of three problems in each of the last two sessions.
- Keep a practice log with review dates for three weeks and revisit at least five patterns through problems you had not solved before.
- Implement LRU Cache from scratch in under 25 minutes with O(1) operations and explain the invariant between the map and the list.


