Coding Interview Questions & Patterns (2026 Guide)
Coding interviews are pattern recognition under time pressure. This guide walks the 12 patterns that show up in 80% of FAANG problems — two pointers, sliding window, BFS/DFS, dynamic programming, heap, backtracking. Each pattern includes the tell (how you recognize a problem belongs to it) and one canonical LeetCode example. Grouped by difficulty of the pattern, not the problems.
Beginner questions
1. Two pointers — when to use it and one canonical problem. Beginner
Tell: the array is sorted, or the problem is about pairs/triplets that satisfy a condition, or you need in-place partitioning. Canonical: Two Sum (sorted variant). Left/right converging pointers, move the one whose value contributes to closing the gap. Complexity O(n) with no extra space.
def twoSumSorted(nums, target):
l, r = 0, len(nums) - 1
while l < r:
s = nums[l] + nums[r]
if s == target: return [l, r]
if s < target: l += 1
else: r -= 1
return []
2. Sliding window — when to use it. Beginner
Tell: 'longest / shortest / count' subarray or substring satisfying a condition. Two variants: fixed-size (window of exactly k) and variable-size (grow until condition breaks, shrink from left until condition holds again). Canonical: longest substring with at most k distinct characters — grow the right pointer, shrink the left when count of distinct exceeds k. O(n).
Practice these live, in your voice
MiPrep's practice mode turns your resume into a rehearsed answer set. Talk through the idioms the way top-tier interviewers score.
Download MiPrep 🔒 Interview audio is never stored on our serversIntermediate questions
3. Binary search — the tell beyond 'sorted array.' Intermediate
Tell: sorted array OR a monotonic function of the answer (as answer increases, some condition monotonically flips from true to false). The second case is 'binary search on answer' — problems like 'minimum capacity to ship packages within D days' or 'find smallest k such that we can distribute n items.' Write the invariant on the whiteboard: what does 'l' mean, what does 'r' mean, what condition are we searching for.
4. BFS vs DFS — when to pick which. Intermediate
BFS: shortest path in unweighted graph, level-by-level exploration, minimum number of steps. Uses a queue. DFS: reachability, connected components, cycle detection, tree traversal, path enumeration. Uses recursion or an explicit stack. Both O(V + E). Mistake to avoid: using BFS for shortest path in a weighted graph — use Dijkstra instead.
5. Heap — when to reach for it. Intermediate
Tell: 'k largest,' 'k smallest,' 'top-k,' or a streaming median. Min-heap of size k for k-largest (pop smallest each time you exceed k). Max-heap for the mirror case. Python's heapq is min-heap only — negate values for max-heap. Complexity: O(n log k) for k-largest of n items. Beats O(n log n) sort when k << n.
6. Prefix sum — the simple pattern with high leverage. Intermediate
Tell: repeated range-sum queries or 'subarray sum equals K.' Precompute prefixes in O(n), answer range sum in O(1). For 'subarray sum equals K,' maintain a hashmap of prefix-sum → count, check for (current_prefix - K) in the map. O(n) single-pass.
Advanced questions
7. Dynamic programming — the recognition heuristic. Advanced
Tell: (1) optimal substructure — the optimal answer decomposes into optimal sub-answers, (2) overlapping subproblems — the same sub-answers get re-computed if you recurse naively. Two implementations: top-down memoization (natural recursion + cache) or bottom-up tabulation (iterate over state space). Start with the recurrence: 'dp[i] = best answer considering first i items.' Then define the transition. Complexity = state space × transition cost.
# Longest increasing subsequence — O(n log n)
from bisect import bisect_left
def lengthOfLIS(nums):
tails = []
for n in nums:
i = bisect_left(tails, n)
if i == len(tails): tails.append(n)
else: tails[i] = n
return len(tails)
8. Backtracking — when it's the pattern. Advanced
Tell: 'find all X' or 'count all ways' where you build the answer incrementally and undo when a partial answer can't lead to a valid full answer. Canonical: permutations, N-queens, sudoku solver. Template: choose → recurse → un-choose. Prune early — the whole point is to skip subtrees that can't produce valid answers.
def permute(nums):
result = []
def backtrack(path, remaining):
if not remaining:
result.append(path[:])
return
for i, n in enumerate(remaining):
path.append(n)
backtrack(path, remaining[:i] + remaining[i+1:])
path.pop()
backtrack([], nums)
return result
9. Union-find (DSU) — when it's the trick. Advanced
Tell: graph connectivity, dynamic groupings, 'given edges added one at a time, when do two nodes become connected.' Implement with path compression + union by rank — nearly O(1) amortized per operation. Canonical: number of connected components, Kruskal's minimum spanning tree.
10. Topological sort — recognizing the pattern. Advanced
Tell: 'order tasks/courses/dependencies subject to prerequisites.' Two implementations: Kahn's algorithm (BFS, in-degree queue) or DFS with post-order. Cycle detection falls out — if any node still has in-degree > 0 at the end (Kahn's) or you visit a node currently on the DFS stack, there's a cycle.
11. Bit manipulation — the small pattern that surprises. Advanced
XOR tricks: a ^ a = 0, a ^ 0 = a. Find the single number in an array where every other appears twice: XOR everything, answer is the unique one. n & (n-1) clears the lowest set bit — useful for counting set bits (Brian Kernighan's algorithm). Bitmask DP: represent a subset of ≤20 elements as an int, transition by flipping bits.
12. How do you handle 'I don't recognize the pattern' in the interview? Advanced
Talk through the problem structure aloud: input shape, output shape, constraints. Ask about constraints if they weren't given — n < 20 signals bitmask or backtracking, n < 500 signals O(n²) DP, n = 1M signals O(n log n) at most. Try the brute-force first, then ask 'what's redundant.' The interviewer would rather see O(n²) with correct reasoning than an incorrect O(n log n).
Common mistakes candidates make
- Coding before understanding — clarify inputs, outputs, and constraints for 2-3 minutes before writing.
- Off-by-one on binary search bounds — always write the loop invariant before writing the loop.
- Not stating complexity — the interviewer scores it whether you say it or not; better to say it.
- Silence during the solve — the interviewer needs to hear your reasoning to score you.
- Optimizing prematurely — get a correct brute-force, then improve.
Study strategy
Four-week plan. Week 1: master 3 patterns (two pointers, sliding window, binary search) — 5 problems each. Week 2: BFS/DFS + heap + prefix sum — 5 problems each. Week 3: DP + backtracking — 8 problems each. Week 4: mixed timed sets — 3 problems in 90 minutes, then review. Solve on paper first, then type. Real interviews test paper-adjacent thinking more than IDE fluency.
Do timed mocks with MiPrep before the real thing
Upload your resume and target job description. MiPrep generates a rehearsed answer set in your voice from your own projects — so mock interviews sound like real ones.
Get MiPrep — free 🔒 Interview audio is never stored on our servers