All resources
Technical15 min read

Technical interview patterns

The recurring coding patterns behind most FAANG DSA questions — learn the pattern, not 500 problems.

Grinding random problems is inefficient. Almost every coding-round question is an instance of a known pattern, and there are far fewer patterns than there are problems. Learn to recognise the pattern from the problem statement and you turn "I have never seen this before" into "this is a sliding window problem". This guide covers the patterns worth mastering, the signal words that identify each one, and how to practise so recognition becomes automatic.

Why patterns beat problem count

The common advice is to solve some large number of problems. The number is the wrong target. Two candidates who have each done two hundred problems can have completely different outcomes: the one who did them shuffled and forgot most of them, and the one who worked in blocks by pattern and can now classify an unseen problem in thirty seconds.

Recognition is the actual skill under test. In a live round you get a problem you have not seen, and the first two minutes decide the round — either you identify the shape and start reasoning toward a known technique, or you flail. Everything below is organised to build that classification reflex.

A realistic target is around one hundred fifty well-chosen problems worked in pattern blocks, with the harder ones revisited. That beats five hundred shuffled problems comfortably, and it fits inside a working engineer schedule.

Arrays and strings: two pointers, sliding window, prefix sums

The highest-frequency family in coding rounds. Two pointers walk a sorted array from both ends or at different speeds; sliding window maintains a contiguous range that expands and contracts; prefix sums precompute cumulative totals so any range query becomes constant time.

The unifying idea is avoiding the nested loop. Most of these problems have an obvious quadratic solution, and the pattern is the linear one. Say the brute force out loud, state its complexity, then improve it — interviewers explicitly reward that progression.

  • Two pointers — pair sums in a sorted array, removing duplicates in place, container with most water, reversing or partitioning in place.
  • Fast and slow pointers — cycle detection in a linked list, finding the middle, finding a duplicate number.
  • Sliding window — longest substring without repeating characters, minimum window substring, longest repeating character replacement, maximum sum subarray of size k.
  • Prefix sums — subarray sum equals k, range sum queries, product of array except self.
  • Signals: "sorted array", "contiguous subarray", "longest or shortest substring", "in place", "without extra space".

Hashing

Not glamorous and extremely high-yield. A hash map turns a linear scan into a constant-time lookup and is the difference between quadratic and linear in a large fraction of problems. Frequency counting, deduplication, grouping, and complement lookups all reduce to it.

The interview-relevant subtlety is knowing when a hash map is the wrong choice: when you need ordering, when you need range queries, or when the memory overhead matters. Being able to say why you are paying O(n) space is part of the score.

  • Frequency maps — anagram checks, top k frequent elements, first unique character.
  • Complement lookups — two sum, pairs with a given difference.
  • Grouping by a computed key — group anagrams, isomorphic strings.
  • Set membership — longest consecutive sequence, containing duplicates.
  • Signals: "count", "frequency", "duplicate", "have we seen", "group by".

Binary search, including on the answer space

Everyone knows binary search on a sorted array. The variant that separates candidates is binary search on the answer space: when the question asks you to minimise a maximum or maximise a minimum, and there is a monotonic feasibility check, you binary search over the possible answers rather than over an array.

The classic framing is: can we achieve the goal with budget X? If the answer is monotonic — feasible for every value above some threshold and infeasible below — you can binary search the threshold. Recognising this is a strong senior signal because most candidates never make the leap from searching data to searching answers.

Get the boundary conditions right and practise them deliberately. Off-by-one errors in the loop condition are the single most common way candidates lose an otherwise correct binary search.

  • Classic — search in a rotated sorted array, find first and last position, search insert position.
  • On the answer space — koko eating bananas, split array largest sum, capacity to ship packages within d days, minimum days to make bouquets.
  • Signals: "sorted", "rotated", "minimise the maximum", "maximise the minimum", "smallest value such that".

Trees and graphs

Trees are the friendliest topic to prepare because the recursion is uniform: most tree problems are a depth-first traversal with a small amount of work at each node. Get comfortable writing pre-order, in-order and post-order without hesitating, and know which one a given problem needs.

Graphs extend the same traversals with a visited set. The main additions worth explicit practice are topological sort for dependency ordering, union-find for connectivity and grouping, and Dijkstra for weighted shortest paths. Grid problems are graph problems in disguise — treat each cell as a node with up to four neighbours and the pattern becomes obvious.

  • Tree DFS — maximum depth, path sum, diameter, lowest common ancestor, validate a BST.
  • Tree BFS — level-order traversal, right side view, minimum depth, zigzag traversal.
  • Graph traversal — number of islands, clone graph, word ladder, rotting oranges, flood fill.
  • Topological sort — course schedule, alien dictionary, build ordering.
  • Union-find — number of connected components, redundant connection, accounts merge.
  • Signals: "shortest path in an unweighted graph" means BFS; "all paths" or "explore fully" means DFS; "prerequisites" or "ordering" means topological sort; "are these connected" or "merge groups" means union-find.

Heaps and intervals

A heap gives you the smallest or largest element in logarithmic time, which is exactly what you want for top-k, merging sorted streams, and running statistics. The two-heap trick — a max-heap for the lower half and a min-heap for the upper — solves the running median family.

Interval problems are a separate small family with a reliable opening move: sort by start time, then sweep. Merging, inserting, and counting overlaps all follow from that. Meeting-rooms style problems combine both, using a heap to track the earliest ending interval while sweeping.

  • Heaps — top k frequent elements, k closest points to origin, merge k sorted lists, task scheduler.
  • Two heaps — find median from a data stream, sliding window median.
  • Intervals — merge intervals, insert interval, non-overlapping intervals, meeting rooms.
  • Signals: "top k", "k closest", "k largest", "median of a stream", "merge k", "overlapping ranges", "schedule".

Dynamic programming

The topic candidates fear most, largely because it is usually taught as a list of tricks instead of a method. It is a method. Find the recurrence first, in plain language: what is the answer for state i in terms of smaller states? Write the brute-force recursion. Add memoisation. Only then convert to a bottom-up table if it helps.

Most interview DP falls into a handful of shapes, and the state definition is where the difficulty actually lives. If you can state precisely what dp[i] or dp[i][j] means in one sentence, the transition usually follows in a minute. If you cannot, no amount of staring at the table will help.

In a real interview, a working memoised recursion with correct complexity is a perfectly good answer. Do not burn ten minutes converting to tabulation for constant-factor gains unless the interviewer asks for it.

  • One-dimensional — climbing stairs, house robber, coin change, decode ways, word break.
  • Two-dimensional grid — unique paths, minimum path sum, edit distance, longest common subsequence.
  • Knapsack family — subset sum, partition equal subset sum, target sum, coin change variants.
  • Sequence DP — longest increasing subsequence, longest palindromic substring, maximum product subarray.
  • Signals: "number of ways", "minimum or maximum cost", "can you reach", "longest or shortest subsequence", plus overlapping subproblems in the recursion tree.

Backtracking

Backtracking is systematic exhaustive search with pruning: choose, explore, un-choose. The template barely changes between problems, so the work is in defining the choice at each level and the condition that prunes a branch early.

Be explicit about complexity here, because it is exponential and interviewers want to hear you acknowledge that. Saying "this is O(n times 2 to the n) and the pruning helps in practice but does not change the worst case" is exactly the kind of statement that earns marks.

  • Subsets and combinations — subsets, combination sum, letter combinations of a phone number.
  • Permutations — permutations with and without duplicates, next permutation.
  • Constraint satisfaction — n-queens, sudoku solver, word search, palindrome partitioning.
  • Signals: "all possible", "generate every", "find all combinations or arrangements", "valid configurations".

Reading the prompt: signal words to pattern

Train the mapping deliberately. For the first month of practice, before writing a line of code, say out loud which pattern you think it is and which signal in the prompt told you. Getting this wrong is fine and informative; not doing it at all is what leaves recognition slow.

Naming the pattern in the interview is itself a scored signal. "This is asking for the longest contiguous substring with a constraint, so I am going to use a sliding window" tells the interviewer you have a plan before you write anything, and it gives them a chance to redirect you early if you have misread the problem.

  • “contiguous subarray”, “longest substring”Sliding window
  • “sorted”, “rotated”Binary search
  • “minimise the maximum”, “smallest value such that”Binary search on the answer
  • “top K”, “K closest”, “median of a stream”Heap
  • “count”, “frequency”, “duplicate”Hashing
  • “all combinations”, “generate every”Backtracking
  • “number of ways”, “min/max over choices”Dynamic programming
  • “prerequisites”, “ordering”Topological sort
  • “are these connected”, “merge groups”Union-find
Name the pattern out loud. It tells the interviewer you have a plan before you write a line.

Practise in blocks, not shuffled

Work five to ten problems of a single pattern back to back until the shape is automatic, then move on. Blocked practice builds recognition much faster than a shuffled list, because you are explicitly learning what the pattern looks like from different angles.

Then invert it. Once you have covered the patterns, do mixed sets where you do not know the pattern in advance — that is the interview condition, and it is a different skill from executing a pattern you have been told to use. A good rhythm is blocked practice while learning, mixed practice in the final few weeks.

Redo problems. Solving something once and never returning to it produces the illusion of coverage. Anything you struggled with should come back after a week and again after a month.

Complexity analysis is half the score

State time and space complexity for every solution, unprompted, and be ready to justify both. Candidates who wait to be asked look like they had not thought about it.

Know the trade-off you are making and say it. An O(n) solution using O(n) extra space versus an O(n log n) in-place one is a real decision, and articulating why you chose one is worth more than the choice itself. Also be honest about amortised versus worst case — claiming hash map operations are O(1) worst case is a small error interviewers do notice.

What is scored beyond correctness

A candidate who produces a working optimal solution in silence often scores below one who produces a slightly weaker solution while narrating clearly. The round is a simulation of working with you, not a test with an answer key.

  • Clarify before coding — ask about input ranges, duplicates, empty inputs, and expected behaviour on invalid input.
  • State the brute force and its complexity, then improve. Do not jump silently to the optimal answer.
  • Narrate while coding, but stop narrating when you need to think. Silence you have announced is fine.
  • Test your own code on a small example and at least one edge case before saying you are done.
  • Use real variable names. Single letters everywhere reads as carelessness under pressure.
  • If you are stuck, say what you are stuck on. Interviewers are allowed to help, and how you use a hint is scored.

A ten-week rotation

If you want a schedule rather than a reading list, this covers the material at a sustainable pace for someone working full time. Roughly five problems per pattern in week one of each block, then harder variants.

Arrays & stringsweeks 1–2

two pointers, sliding window, prefix sums

Hashingweek 3
Binary searchweek 4

incl. the answer space

Trees & graphsweeks 5–6

BFS, DFS, topo sort, union-find

Heaps & intervalsweek 7
Dynamic programmingweeks 8–9

one shape at a time

Backtracking + mixedweek 10
Blocked practice while learning; mixed sets at the end, because that is the interview condition.
  • Weeks 1-2 — arrays and strings: two pointers, sliding window, prefix sums.
  • Week 3 — hashing and sets.
  • Week 4 — binary search, including the answer-space variant.
  • Weeks 5-6 — trees, then graphs, topological sort and union-find.
  • Week 7 — heaps and intervals.
  • Weeks 8-9 — dynamic programming, one shape at a time.
  • Week 10 — backtracking, then mixed sets with no pattern given in advance.

Key takeaways

  • Most DSA questions are instances of a small number of patterns — learn the patterns, not a problem count.
  • Roughly one hundred fifty problems worked in blocks beats five hundred shuffled.
  • Map signal words in the prompt to the pattern, and name the pattern out loud in the room.
  • Binary search on the answer space is the highest-value pattern most candidates miss.
  • For DP, define the state in one sentence first; the transition usually follows.
  • State time and space complexity unprompted, and name the trade-off you chose.
  • Clarify, state the brute force, narrate, and test your own code — all of it is scored.

Put it into practice

Run an AI mock interview and get honest, real-time feedback. Seven days of full Pro, no card required.

Start a practice interview