Free · No signup · Bookmark it

Coding Interview Cheat Sheet

The hard part of a coding interview usually isn’t the algorithm — it’s recognizing which one the problem wants. This is a recognition guide: the 17 core patterns with the exact phrases that signal each one, plus a full Big-O reference. Search it, bookmark it, use it the night before.

The 17 core patterns — and how to spot them

Map the wording of the question to a pattern. The “Use it when you see” phrases are the fastest way to narrow down your approach in the first 60 seconds.

Arrays & Strings

Two Pointers

Use it when you see: a sorted array, “find a pair/triplet summing to target,” “remove duplicates in place,” or “is it a palindrome.”

Two indices moving toward each other (or same direction). Time O(n), space O(1).
Arrays & Strings

Sliding Window

Use it when you see: “longest/shortest contiguous substring/subarray,” “max sum of size k,” or “at most K distinct.”

Expand/shrink a window over the sequence. Time O(n), space O(1) or O(k).
Linked Lists

Fast & Slow Pointers

Use it when you see: “detect a cycle in a linked list,” “find the middle node,” or “happy number.”

One pointer moves 2x the other. Time O(n), space O(1).
Arrays & Strings

Merge Intervals

Use it when you see:overlapping intervals,” “merge,” “meeting rooms,” or “insert an interval.”

Sort by start, then merge. Time O(n log n), space O(n).
Arrays & Strings

Cyclic Sort

Use it when you see: an array of numbers in the range 1..n, “find the missing/duplicate number,” or “in-place, O(1) space.”

Place each number at its index. Time O(n), space O(1).
Linked Lists

In-place Reversal

Use it when you see:reverse a linked list,” “reverse a sublist,” or “reverse every k nodes.”

Re-point next pointers as you walk. Time O(n), space O(1).
Trees & Graphs

BFS

Use it when you see:level order traversal,” “shortest path in an unweighted graph,” or “minimum number of steps.”

Queue, explore neighbors level by level. Time O(V+E), space O(V).
Trees & Graphs

DFS

Use it when you see: “all paths,” “connected components,” “does a path exist,” or “flood fill.”

Recurse / explicit stack. Time O(V+E), space O(V).
Heaps & Top-K

Two Heaps

Use it when you see:median of a data stream,” “find the median,” or “balance two halves.”

Max-heap (low half) + min-heap (high half). Time O(log n)/op.
DP & Backtracking

Subsets / Backtracking

Use it when you see:all combinations/permutations/subsets,” “generate all,” “N-Queens,” or “Sudoku.”

Choose / explore / un-choose. Time up to O(2^n) or O(n!).
Search & Sort

Modified Binary Search

Use it when you see: a sorted (or rotated sorted) array, “find element/boundary,” or a required O(log n).

Halve the search space each step. Time O(log n), space O(1).
Heaps & Top-K

Top K Elements

Use it when you see: “K largest/smallest/most frequent,” or “the Kth element.”

Keep a heap of size K. Time O(n log k), space O(k).
Heaps & Top-K

K-way Merge

Use it when you see: “merge K sorted lists/arrays,” or “smallest range covering K lists.”

Min-heap of list heads. Time O(n log k), space O(k).
Trees & Graphs

Topological Sort

Use it when you see: “course schedule,” “build order,” “dependencies,” or a DAG.

Kahn’s algorithm (in-degrees + queue). Time O(V+E).
DP & Backtracking

Dynamic Programming

Use it when you see:count the ways,” “min/max cost,” “can you reach,” or “longest/shortest with choices.”

Overlapping subproblems + optimal substructure. Time varies (often O(n·m)).
DP & Backtracking

Greedy

Use it when you see: “maximize/minimize” with a single forward pass, “jump game,” or interval scheduling.

Take the locally optimal choice. Time often O(n log n).
Trees & Graphs

Union-Find (DSU)

Use it when you see: “number of connected components/islands,” “are two nodes connected,” or “grouping.”

Union by rank + path compression. Time ~O(1) amortized/op.

No pattern matches that search. Try a phrase from the problem, like “sorted array” or “all permutations.”

Big-O cheat sheet — data structures

Average-case time complexity of the common operations. Reach for the hash map by default; know where the others win.

Data structureAccessSearchInsertDeleteSpace
ArrayO(1)O(n)O(n)O(n)O(n)
Dynamic arrayO(1)O(n)O(1)*O(n)O(n)
Hash table / mapO(1)O(1)O(1)O(n)
Stack / QueueO(n)O(n)O(1)O(1)O(n)
Linked list (singly)O(n)O(n)O(1)O(1)O(n)
Balanced BSTO(log n)O(log n)O(log n)O(log n)O(n)
Heap / Priority queueO(n)O(log n)O(log n)O(n)
TrieO(L)O(L)O(L)O(A·N)

* amortized · L = key length · A = alphabet size · worst-case for hash table and BST is O(n).

Big-O cheat sheet — algorithms

Know these cold — interviewers expect you to state the complexity of what you write.

AlgorithmTimeSpaceNote
Binary searchO(log n)O(1)Array must be sorted
Merge / Heap sortO(n log n)O(n)/O(1)Guaranteed n log n
Quicksort (avg)O(n log n)O(log n)Worst case O(n²)
BFS / DFSO(V+E)O(V)Graph traversal
Dijkstra (heap)O((V+E) log V)O(V)Non-negative weights
Topological sortO(V+E)O(V)DAG only
Subsets / PermutationsO(2^n)/O(n!)O(n)Exponential by nature

FAQ

How do I recognize which pattern a problem needs?

Read for trigger phrases. “Sorted array” + “find a pair” → Two Pointers. “Longest contiguous substring” → Sliding Window. “Numbers 1 to n” → Cyclic Sort. “All combinations” → Backtracking. “Course schedule / dependencies” → Topological Sort. The cards above list these phrases per pattern — that recognition step is usually the whole game.

What is the time complexity of a hash table lookup?

O(1) on average, O(n) worst case under heavy collisions. Insert and delete are also O(1) average — which is why a hash map is the default for membership checks and frequency counts.

How many patterns do I actually need to know?

These 17 cover the large majority of questions asked at most companies. Master the recognition triggers and one clean template per pattern, and you can decompose almost any new problem into something you’ve seen.

Is this cheat sheet free to use and share?

Yes — completely free, no signup, works on any device. Bookmark it or link to it. It’s published by CoPilot Interview as a study reference.

Going from “I know the pattern” to “I can do it live”

Knowing the cheat sheet and performing under a live screen-share are different skills. CoPilot Interview is a desktop AI assistant that gives real-time, structured help during actual coding rounds — approach, code, and Big-O — with a permanent free tier. Honest prep support, not concealment.

See how it works