LeetCode Algorithms and Data Structures: The List That Covers Most Problems
Most LeetCode problems use about ten algorithm families, not hundreds of named algorithms. Hashing, two pointers, sliding window, binary search, sorting, depth first search, breadth first search, heaps and dynamic programming cover the large majority.
The names matter less than the recognition. LeetCode almost never asks you to write a named algorithm. It describes a situation, and you have to see which family fits.
Learn the data structures first. Every algorithm below runs on an array, a string, a hash map, a tree, a graph or a heap.
The ten families that appear most
| Family | What it does | Example problem |
|---|---|---|
| Hashing | Stores and looks up a key in constant average time | Two Sum |
| Two pointers | Moves two indexes through one sorted array | Container With Most Water |
| Sliding window | Grows and shrinks a range over an array | Longest Substring Without Repeating Characters |
| Binary search | Cuts a sorted range in half each step | Search in Rotated Sorted Array |
| Sorting | Orders the data so a single scan solves it | Merge Intervals |
| Depth first search | Follows one path to the end, then backs up | Number of Islands |
| Breadth first search | Visits nodes level by level | Word Ladder |
| Heap | Keeps the k largest or smallest items | Top K Frequent Elements |
| Dynamic programming | Reuses answers to smaller cases | Coin Change |
| Backtracking | Builds a partial answer and undoes bad choices | N-Queens |
If you know these ten well, most medium problems become readable. You will still have to think, but you will know where to start.
The data structures you need first
An algorithm is only a way to move through a data structure. So learn the structures before the tricks.
- Arrays and strings. Almost every problem starts here.
- Hash map and hash set. These turn many O(n squared) scans into O(n).
- Stack and queue. A stack drives depth first search, a queue drives breadth first search.
- Linked list. Mostly pointer work, such as reversing or finding a cycle.
- Binary tree. Inorder, preorder and postorder traversal are the base skills.
- Graph. Store it as an adjacency list, then run depth first or breadth first search.
- Heap. A structure that gives you the smallest or largest item in O(log n).
Our data structures course for coding interviews walks through each one with code.
Algorithms that show up less often
These are worth learning after the ten above, not before.
- Union find. Also called disjoint set. It appears in graph grouping and cycle problems.
- Topological sort. Orders tasks that depend on each other, as in Course Schedule.
- Dijkstra's algorithm. Shortest path when edges have different weights.
- Trie. A prefix tree for word search and autocomplete questions.
- Bit manipulation. XOR tricks and bitmasks for a small set of problems.
Segment trees, Fenwick trees, KMP and Rabin-Karp are real algorithms, but they are rare in interviews. Skip them until the common set is solid.
What interviewers ask for on top of the algorithm
Naming the right algorithm is only half the answer. You also have to state the cost and defend it.
For every problem, say the time and space complexity out loud. Then say why you chose that structure over another one. A correct solution with no complexity analysis reads as an incomplete answer.
Sorting and searching come up in almost every round, so start there. We cover the ranking in top algorithms for sorting and searching in interviews.
How to Prepare
- Learn patterns, not problem counts. Grouping problems by shape beats grinding a random list. Grokking the Coding Interview organizes questions into the patterns above.
- Start with a small, ranked set. Grokking the 75 Top Coding Interview Questions covers each family once, which is enough for most screens.
- Solve five problems per family before moving on. Recognition comes from repetition inside one family, not from variety.
- Write the complexity before you write the code. If you cannot state the target cost, you have not chosen an approach yet.
- Redo the problems you failed after a week. A second attempt shows whether you learned the pattern or memorized the answer.
- Read the common pattern list. What are the most common LeetCode patterns? maps problem wording to the family it belongs to.
- Decide how much LeetCode you need. Is using LeetCode worth it? sets out where the platform helps and where it does not.

GET YOUR FREE
Coding Questions Catalog

$123

$197

$72