How to Recognise Coding Patterns

A decision guide that maps problem signals to the right pattern — and a repeatable process for any interview question.

Beginner 4 min readLesson 1 of 25

There are thousands of coding-interview problems but only a couple of dozen patterns behind them. Strong candidates don't memorise problems; they recognise the pattern from a few signals in the statement, then adapt a template they know cold.

This track covers each pattern with: when to use it, a reusable template in Java, Python and TypeScript, worked examples, and a practice list ordered by difficulty.

The signal → pattern map

If the problem mentions…ThinkLesson
Sorted array, pair/triplet with a target sum, in-place partitionTwo pointersTwo pointers
Linked list cycle, middle, "happy number"Fast & slow pointersFast & slow
Longest/shortest contiguous subarray or substring with a constraintSliding windowSliding window
Range sums, "subarray sum equals k"Prefix sum + hash mapPrefix sum
Overlapping intervals, meetings, merging rangesMerge intervalsMerge intervals
Array of numbers in range 1..n, find missing/duplicateCyclic sortCyclic sort
Next greater/smaller element, histogram, stock spanMonotonic stackMonotonic stack
Sorted / rotated array, "minimum x that works"Modified binary searchBinary search
Reverse a linked list or part of itIn-place reversalList reversal
Tree level by level, minimum depthTree BFSTree BFS
Tree paths, subtree properties, LCATree DFSTree DFS
Grid islands, connectivity, shortest path in a mazeGraph BFS/DFSGraph patterns
Prerequisites, dependency orderTopological sortTopological sort
Dynamic connectivity, grouping equivalent itemsUnion-FindUnion-Find
Prefixes, dictionary of words, autocompleteTrieTrie
Median of a stream, balance two halvesTwo heapsTwo heaps
Top / smallest / most frequent kHeap of size kTop K
Merge k sorted lists/arraysK-way merge (heap)K-way merge
All combinations, permutations, subsets; constraint puzzlesBacktrackingSubsets & backtracking
Find the unique/missing number, pairs cancelBitwise XORBitwise XOR
Scheduling, intervals, "minimum number of…" with a clear local choiceGreedyGreedy
Choose items under a capacity/budget, subset sums0/1 or unbounded knapsackKnapsack DP
Two strings: LCS, edit distance, interleavingDP on sequencesDP on sequences
Grid paths, palindromic substrings, burst balloonsDP on grids & intervalsGrids & intervals

Constraints tell you the complexity

n up toFeasible complexityLikely technique
10–12O(n!)Permutations / brute force
20–25O(2ⁿ)Subsets, bitmask DP
100–500O(n³)Floyd-Warshall, interval DP
1,000–5,000O(n²)2D DP, nested loops
10⁵–10⁶O(n log n) or O(n)Sorting, heaps, two pointers, sliding window, hashing
10⁹+O(log n) or O(1)Binary search, math

A repeatable process (the "UMPIRE" loop)

  1. Understand. Restate the problem. Ask about input sizes, duplicates, negatives, empty input, sortedness, and what to return. Work a tiny example by hand.
  2. Match. Use the signal table and the constraints to shortlist patterns. Say your reasoning out loud.
  3. Plan. Start with brute force and its complexity, then optimise ("we're re-scanning the window → sliding window"). Agree on the approach before coding.
  4. Implement. Write clean code with good names. Use the template; handle edge cases.
  5. Review. Trace your code on the example and on an edge case (empty, one element, all equal).
  6. Evaluate. State time and space complexity, and mention trade-offs or follow-ups.

How to practise

  • Study one pattern at a time: read the lesson, then solve its practice problems without looking at solutions for 25–30 minutes each.
  • After solving, write down the signal that should have triggered the pattern.
  • Revisit problems after 3 days and after 2 weeks (spaced repetition).
  • Mix patterns once each is familiar — recognising which pattern applies is the real skill.
Key takeaways
  • Recognise patterns from signals in the statement, not from memorised problems.
  • Use the input constraints to infer the target complexity.
  • Follow a consistent process: understand, match, plan, implement, review, evaluate.