Skip to main content

β˜• LeetCode Study Guide

A structured approach to mastering algorithms and data structures for coding interviews β€” with 500+ solved problems across 18 categories.

How to Use This Guide
  1. Follow the 8-week roadmap below from Phase 1 β†’ Phase 4
  2. For each topic, read the pattern explanation first
  3. Solve problems in order of difficulty (Easy β†’ Medium β†’ Hard)
  4. Review your solutions and compare with the ones here
  5. 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.

PatternKey ProblemsWhat You'll Learn
ArraysTwo Sum, Contains Duplicate, Merge Sorted ArrayArray manipulation, hash maps
StringsValid Anagram, Longest Substring, Group AnagramsString processing, frequency counting
Two Pointers3Sum, Container With Most Water, Remove DuplicatesConverging and diverging pointers
Sliding WindowMax Subarray, Min Window SubstringVariable and fixed-size windows

Phase 2: Core Data Structures (Weeks 3-4)​

Goal: Master linked lists, stacks, and search techniques.

PatternKey ProblemsWhat You'll Learn
Linked ListsReverse List, Merge Two Lists, Detect CyclePointer manipulation, fast/slow
StacksValid Parentheses, Min Stack, Daily TemperaturesLIFO processing, monotonic stacks
Binary SearchSearch in Rotated Array, Find Peak ElementO(log⁑n)O(\log n) search, boundary finding
SortingMerge Sort, Quick Sort, Sort ColorsDivide and conquer, partitioning

Phase 3: Trees and Graphs (Weeks 5-6)​

Goal: Conquer tree traversals, graph algorithms, and grid problems.

PatternKey ProblemsWhat You'll Learn
Binary TreesInorder/Level-Order Traversal, Max DepthDFS, BFS, recursion
BSTValidate BST, Kth Smallest, LCABST properties, in-order traversal
GraphsNumber of Islands, Clone Graph, Course ScheduleBFS/DFS, topological sort
Matrix01 Matrix, Rotting Oranges, Spiral MatrixGrid BFS/DFS, direction arrays

Phase 4: Advanced Patterns (Weeks 7-8)​

Goal: Tackle the hardest patterns β€” DP, backtracking, and optimization.

PatternKey ProblemsWhat You'll Learn
Dynamic ProgrammingCoin Change, LIS, House Robber, Edit DistanceState definition, transitions
BacktrackingSubsets, Permutations, N-QueensExplore and backtrack, pruning
GreedyJump Game, Task Scheduler, Meeting RoomsLocal to global optimal
Bit ManipulationSingle Number, Counting Bits, Power of TwoXOR 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 WindowMin Window Substring
"Find in sorted array"Binary SearchSearch Rotated Array
"All combinations/permutations"BacktrackingSubsets, Permutations
"Min/Max cost, # of ways"Dynamic ProgrammingCoin Change
"Connected components"BFS/DFS or Union-FindNumber of Islands
"Level-by-level"BFSLevel-Order Traversal
"Next greater/smaller"Monotonic StackDaily Temperatures
"Top K elements"HeapKth Largest Element
"Prefix lookup"TrieImplement Trie

Time Complexity Quick Reference​

AlgorithmBestAverageWorstSpace
Binary SearchO(1)O(1)O(log⁑n)O(\log n)O(log⁑n)O(\log n)O(1)O(1)
Two PointersO(n)O(n)O(n)O(n)O(n)O(n)O(1)O(1)
Sliding WindowO(n)O(n)O(n)O(n)O(n)O(n)O(k)O(k)
BFS/DFSO(V+E)O(V+E)O(V+E)O(V+E)O(V+E)O(V+E)O(V)O(V)
Merge SortO(nlog⁑n)O(n \log n)O(nlog⁑n)O(n \log n)O(nlog⁑n)O(n \log n)O(n)O(n)
Quick SortO(nlog⁑n)O(n \log n)O(nlog⁑n)O(n \log n)O(n2)O(n^2)O(log⁑n)O(\log n)
Heap Push/Pop-O(log⁑n)O(\log n)O(log⁑n)O(\log n)O(n)O(n)
Hash TableO(1)O(1)O(1)O(1)O(n)O(n)O(n)O(n)
Trie Insert/Search-O(L)O(L)O(L)O(L)O(nΓ—L)O(n \times L)
Union-Find-O(Ξ±(n))O(\alpha(n))O(Ξ±(n))O(\alpha(n))O(n)O(n)

Interview Tips​

5-Step Framework for Any Problem
  1. Clarify β€” Ask about constraints, edge cases, input size, duplicates
  2. Brute Force β€” Start with the simplest solution, clearly state its complexity
  3. Optimize β€” Identify the bottleneck, consider which pattern applies
  4. Code β€” Write clean, readable code with meaningful variable names
  5. 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 (231βˆ’12^{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 500+ problems organized by topic. Each page includes the problem statement, solution code in C#, complexity analysis, and pattern explanations.

CategoryProblemsFocus Areas
πŸ”€ Strings81Pattern matching, palindromes, anagrams, parsing
🌳 Trees76DFS, BFS, BST, tree construction, path problems
πŸ“Š Arrays72Two pointers, sliding window, binary search, prefix sums
🧩 Dynamic Programming431D/2D DP, knapsack, subsequences, intervals
πŸ”’ Math37Number theory, geometry, combinatorics
πŸ”— Linked Lists29Reversal, merge, cycle detection, fast/slow pointers
πŸ—„οΈ SQL29Joins, aggregations, window functions, subqueries
πŸ“ˆ Sorting27Comparison sorts, counting sort, custom comparators
πŸ•ΈοΈ Graphs22BFS, DFS, topological sort, union-find, shortest path
⬜ Matrix19Grid BFS/DFS, rotation, spiral traversal
πŸ”™ Backtracking18Subsets, permutations, constraint satisfaction
πŸ’Ύ Bit Manipulation17XOR, bit counting, masks, power of two
🎯 Greedy16Interval scheduling, activity selection
πŸ—οΈ Design12LRU/LFU cache, iterators, data structure design
πŸ“š Stack10Monotonic stack, expression evaluation, brackets
🌲 Trie3Prefix matching, autocomplete, word search
⛰️ Heap3Priority queue, top-K, merge K sorted
πŸ’» Shell & Misc2Bash one-liners β€” word frequency, regex validation