Follow this in every interview — interviewers grade on process, not just code
Inputs, outputs, constraints, edge cases. Ask about size of n.
Walk through 2-3 examples. Include an edge case. Write them down.
State the obvious O(n²) or O(n!) approach. Don't code it — just say it.
Identify the pattern. Pick the right data structure. State time/space.
Write clean code. Talk while you code. Use meaningful names.
Trace through your code with an example. Check edge cases.
See a signal in the problem → pick the right pattern
What do you need? → Use this
Quick Rules
Need O(1) access? → HashMap or Array
Need sorted order? → BST or sorted array + binary search
Need min/max fast? → Heap
Need undo/backtrack? → Stack
Need level-order? → Queue (BFS)
BFS — Level-order / shortest path
queue = [start]
visited = set(start)
while queue:
node = queue.popleft()
for neighbor in adj[node]:
if neighbor not in visited:
visited.add(neighbor)
queue.append(neighbor)
DFS — Explore all paths / backtrack
def dfs(node, visited):
if node in visited: return
visited.add(node)
# process node
for neighbor in adj[node]:
dfs(neighbor, visited)
left = 0
for right in range(len(arr)):
# expand: add arr[right] to window
while window is invalid:
# shrink: remove arr[left]
left += 1
# update answer
Two Pointers
left, right = 0, len(arr) - 1
while left < right:
if condition met:
# found answer
elif need bigger: left += 1
else: right -= 1
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
Use when: sorted array, monotonic function, answer space is bounded
Time: O(log n) Space: O(1)
Most DP problems fall into one of these categories
Climbing stairs, house robber, coin change
dp[i] = f(dp[i-1], dp[i-2])Unique paths, min path sum, dungeon game
dp[i][j] = f(dp[i-1][j], dp[i][j-1])Edit distance, LCS, palindrome
dp[i][j] = f(s1[i], s2[j], neighbors)0/1 knapsack, subset sum, partition
dp[i][w] = max(skip, take)Matrix chain, burst balloons, palindrome
dp[i][j] = f(dp[i][k], dp[k][j])Max path sum, house robber III, diameter
dfs returns (take, skip) for subtreeDP Checklist
Can I define the answer in terms of smaller subproblems?
Are there overlapping subproblems?
What's my base case?
What order do I fill the table?
Always check these before saying "I'm done"
Empty [], single element, all same, already sorted, reverse sorted, duplicates
Empty "", single char, all same char, palindrome, spaces, unicode, case sensitivity
0, negative, MAX_INT, MIN_INT, overflow, odd/even, floating point
Empty, single node, cycle, two nodes, head/tail operations
Empty, single node, left-skewed, right-skewed, balanced, complete
Disconnected, self-loops, parallel edges, single node, complete graph
Permutations, combinations, subsets, N-Queens
def backtrack(path, choices):
if goal reached:
result.append(path[:])
return
for choice in choices:
if valid(choice):
path.append(choice) # choose
backtrack(path, ...) # explore
path.pop() # unchoose
Key: Choose → Explore → Unchoose (undo the choice)
Jumping straight to code
Clarify → Examples → Brute Force → Optimize → Code
Not talking through your thinking
Narrate your thought process — silence = red flag
Ignoring edge cases
Empty input, single element, duplicates, negative numbers
Over-engineering the solution
Start simple. Optimize only after brute force works.
Not testing your code
Trace through with a small example before saying done
Forgetting time/space complexity
Always state it before coding. Update if you optimize.
Off-by-one errors
Be deliberate with < vs <=, i vs i+1, inclusive vs exclusive
Pro Tips
This programming interview cheat sheet covers the patterns, templates, and strategy you need to ace coding interviews at top tech companies. Instead of memorizing hundreds of LeetCode solutions, learn to recognize the 15 core patterns and apply reusable code templates.
Our coding interview cheat sheet includes a step-by-step problem-solving framework, pattern recognition guide (see signal → use pattern), code templates for BFS/DFS, sliding window, two pointers, binary search, backtracking, and dynamic programming, a data structure picker decision tree, edge cases checklist by data type, complexity quick reference, common interview mistakes to avoid, and time management strategy for 45-minute interviews.
Whether you're preparing for Google, Meta, Amazon, or any top tech company, this technical interview cheat sheet gives you the complete playbook — patterns, templates, and strategy in one view.
A programming interview cheat sheet is a quick-reference guide covering the patterns, templates, and strategies you need to solve coding problems in technical interviews. It includes pattern recognition (see X → use Y), code templates for common algorithms (BFS, DFS, binary search, sliding window, DP), edge cases to check, complexity analysis, and tips for communicating with your interviewer.
The most common patterns are: Two Pointers (sorted arrays, pair sums), Sliding Window (subarrays, substrings), Binary Search (sorted data, monotonic functions), BFS/DFS (trees, graphs), Dynamic Programming (optimal substructure + overlapping subproblems), Backtracking (permutations, combinations), Merge Intervals (overlapping ranges), Monotonic Stack (next greater element), and Prefix Sum (range queries). Recognizing which pattern to apply is the #1 skill.
Follow the 6-step framework: (1) Clarify — ask about inputs, outputs, constraints, and edge cases. (2) Examples — work through 2-3 examples including an edge case. (3) Brute force — state the obvious solution and its complexity. (4) Optimize — identify the right pattern and data structure. (5) Code — write clean code while narrating your thinking. (6) Test — trace through your code with an example and check edge cases.
DP problems fall into 6 main categories: 1D Linear (climbing stairs, house robber), 2D Grid (unique paths, min path sum), String DP (edit distance, LCS), Knapsack (subset sum, partition), Interval DP (matrix chain, burst balloons), and Tree DP (max path sum, house robber III). For each, identify the state, transition, and base case.
Always check: empty input ([], ""), single element, all same values, already sorted / reverse sorted, duplicates, negative numbers, zero, MAX_INT overflow, odd vs even length. For trees: empty tree, single node, left/right-skewed. For graphs: disconnected components, self-loops, cycles. Mentioning edge cases proactively shows thoroughness.
Rough breakdown: Clarify requirements (3 min), work through examples (2 min), discuss approach and complexity (7 min), write code (20 min), test and debug (5 min), Q&A (5 min). If you're stuck for more than 2 minutes, ask for a hint — interviewers expect this. If brute force works and you have time, optimize after.
Practice with an AI interviewer that tests pattern recognition, code quality, and communication — just like a real interview.
Try Crackr freearrow_forward