β LeetCode Study Guide
A structured approach to mastering algorithms and data structures for coding interviews β with 530+ solved problems across 17 categories.
How to Use This Guide
- Follow the 8-week roadmap below from Phase 1 β Phase 4
- For each topic, read the pattern explanation first
- Solve problems in order of difficulty (Easy β Medium β Hard)
- Review your solutions and compare with the ones here
- Use the Pattern Cheat Sheet below when you're stuck
Roadmap Overviewβ
Study Plan by Categoryβ
Phase 1: Fundamentals (Weeks 1-2)β
Goal: Build a strong foundation with arrays, strings, and basic techniques.
| Pattern | Key Problems | What You'll Learn |
|---|---|---|
| Arrays | Two Sum, Contains Duplicate, Merge Sorted Array | Array manipulation, hash maps |
| Strings | Valid Anagram, Longest Substring, Group Anagrams | String processing, frequency counting |
| Two Pointers | 3Sum, Container With Most Water, Remove Duplicates | Converging and diverging pointers |
| Sliding Window | Max Subarray, Min Window Substring | Variable and fixed-size windows |
Phase 2: Core Data Structures (Weeks 3-4)β
Goal: Master linked lists, stacks, and search techniques.
| Pattern | Key Problems | What You'll Learn |
|---|---|---|
| Linked Lists | Reverse List, Merge Two Lists, Detect Cycle | Pointer manipulation, fast/slow |
| Stacks | Valid Parentheses, Min Stack, Daily Temperatures | LIFO processing, monotonic stacks |
| Binary Search | Search in Rotated Array, Find Peak Element | $O(\log n)$ search, boundary finding |
| Sorting | Merge Sort, Quick Sort, Sort Colors | Divide and conquer, partitioning |
Phase 3: Trees and Graphs (Weeks 5-6)β
Goal: Conquer tree traversals, graph algorithms, and grid problems.
| Pattern | Key Problems | What You'll Learn |
|---|---|---|
| Binary Trees | Inorder/Level-Order Traversal, Max Depth | DFS, BFS, recursion |
| BST | Validate BST, Kth Smallest, LCA | BST properties, in-order traversal |
| Graphs | Number of Islands, Clone Graph, Course Schedule | BFS/DFS, topological sort |
| Matrix | 01 Matrix, Rotting Oranges, Spiral Matrix | Grid BFS/DFS, direction arrays |
Phase 4: Advanced Patterns (Weeks 7-8)β
Goal: Tackle the hardest patterns β DP, backtracking, and optimization.
| Pattern | Key Problems | What You'll Learn |
|---|---|---|
| Dynamic Programming | Coin Change, LIS, House Robber, Edit Distance | State definition, transitions |
| Backtracking | Subsets, Permutations, N-Queens | Explore and backtrack, pruning |
| Greedy | Jump Game, Task Scheduler, Meeting Rooms | Local to global optimal |
| Bit Manipulation | Single Number, Counting Bits, Power of Two | XOR tricks, bit masks |
Key Patterns Cheat Sheetβ
When to Use Whatβ
Quick Pattern Recognitionβ
| If you see... | Think... | Example |
|---|---|---|
| "Find pair/triplet with sum" | Two Pointers (sort first) | 3Sum, Two Sum II |
| "Longest/shortest substring" | Sliding Window | Min Window Substring |
| "Find in sorted array" | Binary Search | Search Rotated Array |
| "All combinations/permutations" | Backtracking | Subsets, Permutations |
| "Min/Max cost, # of ways" | Dynamic Programming | Coin Change |
| "Connected components" | BFS/DFS or Union-Find | Number of Islands |
| "Level-by-level" | BFS | Level-Order Traversal |
| "Next greater/smaller" | Monotonic Stack | Daily Temperatures |
| "Top K elements" | Heap | Kth Largest Element |
| "Prefix lookup" | Trie | Implement Trie |
Time Complexity Quick Referenceβ
| Algorithm | Best | Average | Worst | Space |
|---|---|---|---|---|
| Binary Search | $O(1)$ | $O(\log n)$ | $O(\log n)$ | $O(1)$ |
| Two Pointers | $O(n)$ | $O(n)$ | $O(n)$ | $O(1)$ |
| Sliding Window | $O(n)$ | $O(n)$ | $O(n)$ | $O(k)$ |
| BFS/DFS | $O(V+E)$ | $O(V+E)$ | $O(V+E)$ | $O(V)$ |
| Merge Sort | $O(n \log n)$ | $O(n \log n)$ | $O(n \log n)$ | $O(n)$ |
| Quick Sort | $O(n \log n)$ | $O(n \log n)$ | $O(n^2)$ | $O(\log n)$ |
| Heap Push/Pop | - | $O(\log n)$ | $O(\log n)$ | $O(n)$ |
| Hash Table | $O(1)$ | $O(1)$ | $O(n)$ | $O(n)$ |
| Trie Insert/Search | - | $O(L)$ | $O(L)$ | $O(n \times L)$ |
| Union-Find | - | $O(\alpha(n))$ | $O(\alpha(n))$ | $O(n)$ |
Interview Tipsβ
5-Step Framework for Any Problem
- Clarify β Ask about constraints, edge cases, input size, duplicates
- Brute Force β Start with the simplest solution, clearly state its complexity
- Optimize β Identify the bottleneck, consider which pattern applies
- Code β Write clean, readable code with meaningful variable names
- Test β Walk through examples, then check edge cases
Common Edge Cases to Always Check
- Empty input / single element
- All duplicates / all same values
- Already sorted / reverse sorted
- Negative numbers / zero
- Integer overflow ($2^{31} - 1$)
- Null nodes in trees / empty lists
- Disconnected components in graphs
Common Mistakes in Interviews
- Starting to code without discussing the approach first
- Not considering edge cases until asked
- Using global variables when recursion exists
- Off-by-one errors in binary search
- Not handling the base case in DP
- Forgetting to mark nodes as visited in BFS/DFS
Browse All Categoriesβ
Explore 530+ problems organized by topic. Each page includes the problem statement, solution code in C#, complexity analysis, and pattern explanations.
| Category | Problems | Focus Areas |
|---|---|---|
| π Arrays | 45 | Two pointers, sliding window, binary search, prefix sums |
| π³ Trees | 97 | DFS, BFS, BST, tree construction, path problems |
| π€ Strings | 54 | Pattern matching, palindromes, anagrams, parsing |
| π§© Dynamic Programming | 38 | 1D/2D DP, knapsack, subsequences, intervals |
| π Linked Lists | 26 | Reversal, merge, cycle detection, fast/slow pointers |
| π’ Math | 25 | Number theory, geometry, combinatorics |
| ποΈ SQL | 23 | Joins, aggregations, window functions, subqueries |
| π Sorting | 21 | Comparison sorts, counting sort, custom comparators |
| π Backtracking | 16 | Subsets, permutations, constraint satisfaction |
| β¬ Matrix | 16 | Grid BFS/DFS, rotation, spiral traversal |
| πΎ Bit Manipulation | 15 | XOR, bit counting, masks, power of two |
| πΈοΈ Graphs | 11 | BFS, DFS, topological sort, union-find, shortest path |
| π― Greedy | 9 | Interval scheduling, activity selection |
| π Stack | 9 | Monotonic stack, expression evaluation, brackets |
| ποΈ Design | 7 | LRU/LFU cache, iterators, data structure design |
| π² Trie | 3 | Prefix matching, autocomplete, word search |
| π» LeetCode (Misc) | 112 | Mix of patterns and categories |