Coding Patterns You Should Actually Drill

The fastest way to improve at coding interviews is not more problems — it's recognizing which pattern a problem belongs to within the first 60 seconds. The patterns below cover roughly 80% of medium-difficulty interview questions.

The core 15 patterns

  1. Two Pointers — sorted arrays, palindrome checks, pair sums.
  2. Sliding Window — longest/shortest substring, fixed-size subarrays.
  3. Fast & Slow Pointers — cycle detection, finding the middle of a linked list.
  4. Merge Intervals — overlapping intervals, meeting rooms.
  5. Cyclic Sort — finding missing numbers when values are bounded.
  6. In-place Linked List Reversal — reverse a list, reverse in groups.
  7. Tree BFS — level order traversal, zigzag, right-side view.
  8. Tree DFS — path sum, lowest common ancestor, serialization.
  9. Two Heaps — find the median of a stream, scheduling.
  10. Subsets / Permutations — generate all subsets, all anagrams.
  11. Modified Binary Search — search in rotated array, find peak.
  12. Top K Elements — k closest points, k frequent elements.
  13. K-way Merge — merge k sorted lists, smallest range.
  14. Topological Sort — course schedule, alien dictionary.
  15. Dynamic Programming — knapsack, LCS, edit distance.

Pattern recognition cheat sheet

If the problem mentions… try this pattern first:

Signal in the problemPattern
"Sorted array" + "find pair / triple"Two Pointers
"Longest / shortest substring"Sliding Window
"Cycle in linked list"Fast & Slow Pointers
"Merge / overlap intervals"Merge Intervals
"Numbers in 1..N, missing or duplicate"Cyclic Sort
"Reverse a linked list (in groups)"In-place Reversal
"Level-by-level / shortest path on grid"Tree/Graph BFS
"All paths / all combinations"Tree DFS / Backtracking
"Median of a stream"Two Heaps
"All subsets / permutations"Subsets
"Sorted / rotated array search"Modified Binary Search
"Top K / K smallest / K closest"Top K (Heap)
"Merge K sorted things"K-way Merge
"Dependency / order / prerequisite"Topological Sort
"Min/max with overlapping subproblems"Dynamic Programming

This table covers ~80% of medium-difficulty interview problems. Memorize it.

How to drill

For each pattern, do this loop:

  1. Read the canonical example. Understand why the pattern works, not just the steps.
  2. Solve 3–5 variations. Start medium, push to hard.
  3. Re-derive without looking. A week later, can you write the solution from scratch?
  4. Time-box. 25 minutes per problem. If you blow past it, look at the solution, understand it, then re-solve in 24 hours.

If a pattern stops feeling automatic after a week of break, that's normal. Spaced repetition keeps it sharp.

Common mistakes

  • Memorizing solutions instead of patterns. Interviewers will tweak the constraints. If you only know the exact problem, you're stuck.
  • Ignoring complexity analysis. Almost every interviewer asks. Practice stating time/space before you start coding.
  • Coding silently. Narrate your reasoning. The interview is as much about communication as correctness.