interviewpath
  • 0day streak
  • 10total XP
  • Level 1

Focus mode

Pattern recognition and mixed practice

Read alongside

LeetCode 75 study plan

Compact official problem pool for a first mixed pass across the core patterns, used without looking at the section labels first.

Objectives

  • Map common problem signals (sorted input, contiguous range, top-k, dependencies, minimum steps, count the ways) to candidate patterns and their invariants.
  • State, for each candidate, the condition that makes it applicable, such as a monotone predicate, non-negative values, unit weights or overlapping subproblems.
  • Run mixed-practice sessions in which the pattern is unknown in advance, and record which signal led to the right approach.
  • Maintain a review rotation that revisits each pattern through a different problem at increasing intervals.
  • Design stateful data structures by combining a hash map with a linked list, heap or sorted structure, and analyze every operation.
  • Diagnose weak patterns from a practice log and adjust the plan, using official study plans as problem 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.

SignalCandidate patternsCondition or invariant to check
Complement lookup, duplicates, groupinghashing, frequency countingEqual keys identify equivalent items
Pairs in sorted input, in-place partitioningtwo pointersEach move discards candidates that cannot improve the answer
Contiguous subarray or substringsliding window, prefix sumsWindow validity is monotone (often needs non-negative values); otherwise prefix sums with a hash map
Sorted input, or smallest feasible valuebinary search, binary search on the answerA predicate that flips from false to true exactly once
Overlapping ranges, many range updatessorting, interval merging, sweep lineSort key matches the objective
Nested structure, matching, undostackTop is the most recent unresolved item
Next greater or smaller, window extremesmonotonic stack or dequeStored indices stay in monotone order
k largest, running median, merging streamsheap selection, two heapsHeap top is the current extreme; size stays bounded
Reordering a list, cycles, middleslinked-list pointers, fast and slow pointersSave next before rewiring; fast moves twice as far
Hierarchy, subtree answerstree DFS or BFS, BST invariantEach subtree returns a summary its parent can combine
Many prefix queries over wordstrieEach node represents one prefix
Minimum steps, grids, transformationsgraph BFS or DFS, grid as implicit graph, multi-source BFSUnit weights; mark visited on enqueue
Prerequisites, dependenciestopological ordering, cycle detectionAn order exists only for a DAG
Groups merging over timeunion-findUndirected, unions only
Cheapest weighted routeshortest pathsWeight sign decides Dijkstra or Bellman-Ford
All combinations or placementsbacktrackingChoose, recurse, undo; prune early
Count ways, best total over choicesDP (1D, grid, strings, knapsack)Overlapping subproblems with a valid evaluation order
A locally best choice looks safegreedyAn exchange argument exists
Independent halves, k-th order statisticdivide and conquerSubproblems do not overlap; write the recurrence
Parity, small sets encoded as masksbit manipulationWidth and signedness are explicit
Fast operations on changing datastateful designMap 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.

Self-check before you finish

  1. Which signals suggest a sliding window, and what condition makes it valid?
  2. When does a minimum-steps problem need Dijkstra instead of BFS?
  3. Which signals point to DP rather than greedy, and how would you check?
  4. Which patterns did you recognize late in your last mixed session, and why?
  5. Why is reviewing a pattern through a new problem more useful than re-solving an old one?
  6. What invariant links the hash map and the linked list in an LRU cache?