Vasu Patel logoVasu Patel
← Python DSA — Interview Prep
All chapters in this track
  1. 010. How FAANG Interviews Work
  2. 021. Big-O Complexity
  3. 032. Arrays & Strings
  4. 043. Hashing
  5. 054. Stacks & Queues
  6. 065. Linked Lists
  7. 076. Binary Search
  8. 087. Trees
  9. 098. Heaps
  10. 109. Graphs
  11. 1110. Recursion & Backtracking
  12. 1211. Dynamic Programming
  13. 1312. Sorting & Advanced Search
  14. 1413. Tries
  15. 1514. Interview Patterns Cheat Sheet

Chapter 15 of 15

14. Interview Patterns Cheat Sheet

Signal → Pattern Mapping

You hear / see...Pattern to useKey data structure
Sorted array + pair sumTwo pointers—
Subarray/substring + constraintSliding windowdefaultdict(int)
Range sum on static arrayPrefix sumsList
Max subarray sumKadane'sTwo variables
Sorted + find positionBinary searchbisect
"Minimum X such that feasible(X)"Binary search on answerFeasibility function
Count/find with complementHash map lookupdict
Frequency / group / top-KCounter / heapCounter, heapq
Matching brackets / undoStacklist
Next greater/smaller elementMonotonic stacklist
Level-by-level / minimum depthBFSdeque
Any path / all paths / DFSDFS / backtrackingRecursion + stack
Connected componentsDFS / Union-FindUnionFind
Shortest path (unweighted)BFSdeque
Shortest path (weighted)Dijkstraheapq
Dependency order / cycle?Topological sortdeque + in-degree
Optimal substructure + overlappingDynamic programming1D/2D array + @cache
Prefix matching / autocompleteTrieTrieNode

Common Mistakes to Avoid

# ❌ Off-by-one in binary search
while l < r:
    mid = (l + r) // 2
    r = mid      # correct for lower-bound
    # r = mid - 1  ← wrong, skips mid when it could be the answer

# ❌ Forgetting to snapshot in backtracking
result.append(path)    # WRONG — path is mutable, will be empty at end
result.append(path[:]) # CORRECT — snapshot at this moment

# ❌ Mutating a list while iterating it
for x in arr:
    if condition: arr.remove(x)   # WRONG — skips elements

# ❌ Wrong recursion base case
def dfs(node):
    # missing: if not node: return
    for nb in graph[node]:        # crashes on None
        dfs(nb)

# ❌ Using list.pop(0) for a queue — O(n)
queue = []
queue.pop(0)           # WRONG — use deque.popleft()

from collections import deque
q = deque()
q.popleft()            # CORRECT — O(1)

Space/Time Complexity for Every Structure

StructureAccessSearchInsertDeleteSpace
list (array)O(1)O(1)O(n)O(n)O(1)O(1)†O(n)O(n)O(n)O(n)
dict / setO(1)O(1)O(1)O(1)O(1)O(1)†O(1)O(1)O(n)O(n)
Sorted listO(1)O(1)O(log⁡n)O(\log n)O(n)O(n)O(n)O(n)O(n)O(n)
Stack (list)O(1)O(1) top—O(1)O(1)†O(1)O(1)O(n)O(n)
Queue (deque)O(1)O(1) ends—O(1)O(1)O(1)O(1)O(n)O(n)
Heap (heapq)O(1)O(1) min—O(log⁡n)O(\log n)O(log⁡n)O(\log n)O(n)O(n)
BST (balanced)—O(log⁡n)O(\log n)O(log⁡n)O(\log n)O(log⁡n)O(\log n)O(n)O(n)
Trie—O(L)O(L)O(L)O(L)O(L)O(L)O(n⋅L)O(n \cdot L)
Graph (adj list)—O(V+E)O(V+E)O(1)O(1)O(V)O(V)O(V+E)O(V+E)

† Amortised


FAANG Difficulty Tiers

TierWhat it testsTypical companies
EasyPattern recognition: two-sum, valid parens, reverse linked listAll FAANG (warm-up)
MediumCombine patterns: sliding window + hash, BFS + visited, DP 1DGoogle, Meta, Amazon
HardAdvanced DP (2D, bitmask), graph algorithms, monotonic structuresGoogle, Jane Street

In FAANG interviews, the goal is usually one medium solved cleanly and explained well. A perfect medium beats a scrambled hard.


Last-Minute Checklist (Before Every Interview)

□ Ask clarifying questions before writing any code
□ State the brute force approach and its complexity first
□ Explain your optimised approach before coding
□ Name variables descriptively (not 'a', 'b', 'x')
□ Write the base case of recursion first
□ Walk through your code with the given example
□ Test edge cases: empty input, single element, all same, negative numbers
□ State time AND space complexity for your final solution
□ Ask: "Does this solution meet your expectations?"

End of Python DSA — FAANG Interview Prep — August 2026