Published on

LeetCode Interview Preparation Crash Course

Authors
  • avatar
    Name
    Gene Zhang
    Twitter

LeetCode Interview Preparation Crash Course

A comprehensive collection of curated LeetCode problems organized by pattern and data structure to efficiently prepare for technical interviews. Each problem includes detailed explanations, multiple approaches, time/space complexity analysis, and key insights.

How to Use This Guide

  1. Start with fundamentals - Begin with Array, Two Pointers, and Binary Search
  2. Master patterns - Focus on understanding the pattern, not memorizing solutions
  3. Practice consistently - Do at least 1-2 problems daily
  4. Review regularly - Revisit problems to reinforce patterns
  5. Code without looking - Try to solve from memory to ensure understanding

Study Plan Recommendation

Week 1-2: Fundamentals

  • Array & Sliding Window
  • Two Pointers
  • Binary Search
  • Stack & Queue

Week 3-4: Trees & Graphs

  • Binary Tree
  • Graph Algorithms (BFS, DFS, Topological Sort)

Week 5-6: Advanced Patterns

  • Dynamic Programming
  • Backtracking
  • Heap/Priority Queue

Week 7-8: Specialized Topics

  • Trie
  • Greedy Algorithms
  • Sorting Algorithms
  • String Manipulation

šŸ“š Topics Overview

1. Array (7 problems)

Key Patterns: Kadane's Algorithm, Prefix/Suffix, Sliding Window, Monotonic Deque, Intervals

  • Two Sum (LC 1) - Hash map for pair finding
  • Maximum Subarray (LC 53) - Kadane's algorithm for max sum subarray
  • Merge Intervals (LC 56) - Sorting + merging intervals
  • Maximum Gap (LC 164) - Bucket sort optimization
  • Contains Duplicate II (LC 219) - Sliding window with hash map
  • Product of Array Except Self (LC 238) - Prefix/suffix products
  • Sliding Window Maximum (LC 239) - Monotonic deque for window extremes
  • Flatten 2D Vector (LC 251) - Iterator design pattern
  • Pour Water (LC 755) - Simulation with two-pointer

When to use: Array traversal, subarray problems, window-based optimization, interval problems


2. Two Pointers (2 problems)

Key Patterns: Left-Right pointers, Fast-Slow pointers, Greedy movement

  • Container With Most Water (LC 11) - Greedy two-pointer strategy
  • 3Sum (LC 15) - Two pointers with sorting
  • Trapping Rain Water (LC 42) - Two pointers tracking max heights

When to use: Sorted arrays, pair finding, optimization problems


3. Binary Search (6 problems)

Key Patterns: Standard binary search, Rotated array search, Finding boundaries, Median finding

When to use: Sorted/rotated arrays, finding boundaries, optimization (minimize/maximize)


4. Binary Tree (5 problems)

Key Patterns: DFS traversals, BFS level-order, Recursion, BST properties

When to use: Tree problems, hierarchical data, path finding


5. Graph (13 problems)

Key Patterns: DFS/BFS, Cycle detection, Topological sort, Connected components, Shortest path

When to use: Relationship problems, dependencies, reachability, shortest paths


6. Dynamic Programming (8 problems)

Key Patterns: Optimal substructure, Overlapping subproblems, State transitions

When to use: Optimization problems, counting problems, decision-making with constraints


7. Backtracking (7 problems)

Key Patterns: Choose-Explore-Unchoose, State restoration, Constraint satisfaction

When to use: Generating combinations/permutations, constraint satisfaction, exhaustive search


8. Heap / Priority Queue (7 problems)

Key Patterns: Top K, K-way merge, Two heaps, Streaming median

When to use: Top K problems, merging sorted data, streaming data, priority-based processing


9. Trie (2 problems)

Key Patterns: Prefix operations, Dictionary operations, Word search optimization

When to use: Prefix matching, autocomplete, dictionary operations, word search optimization


10. Stack & Queue (3 problems)

Key Patterns: Matching pairs, Monotonic stack, Next greater/smaller element

  • Valid Parentheses (LC 20) - Stack for matching
  • Min Stack (LC 155) - Auxiliary stack for O(1) operations
  • Daily Temperatures (LC 739) - Monotonic stack

When to use: Matching/balancing, maintaining order, next greater/smaller problems


11. Greedy (3 problems)

Key Patterns: Local optimal choices, Proof of correctness, Scheduling

When to use: Optimization where local choices lead to global optimum, scheduling


12. Sorting (2 problems)

Key Patterns: Divide and conquer, Partitioning, Comparison-based sorting

  • Merge Sort - Stable O(n log n) sort
  • Quick Sort - In-place O(n log n) average sort

When to use: Understanding sorting fundamentals, custom comparators, external sorting


13. String (5 problems)

Key Patterns: Sliding window, Character frequency, Two pointers, Palindrome, Trie

When to use: Substring problems, character manipulation, pattern matching


14. Linked List (3 problems)

Key Patterns: Two pointers, Dummy node, In-place reversal, LRU design

  • Reverse Linked List II (LC 92) - In-place reversal
  • LRU Cache (LC 146) - Doubly linked list + hash map
  • Sort Linked List (LC 148) - Merge sort for linked lists
  • Intersection of Two Linked Lists (LC 160) - Two pointers

When to use: List manipulation, reversal, sorting without arrays


15. Divide and Conquer (1 problem)

Key Patterns: Break into subproblems, Combine solutions

  • Sort Linked List (LC 148) - Merge sort pattern

When to use: Problems that can be broken into independent subproblems


šŸŽÆ Quick Reference: Pattern Recognition

When you see these keywords, think:

  • "Contiguous subarray" → Sliding Window, Kadane's Algorithm
  • "Two sum, three sum" → Two Pointers, Hash Map
  • "Sorted array" → Binary Search, Two Pointers
  • "Tree traversal" → DFS, BFS
  • "Shortest path" → BFS, Dijkstra
  • "Connected components" → DFS, BFS, Union-Find
  • "Optimal/Maximum/Minimum with choices" → Dynamic Programming, Greedy
  • "All possible combinations" → Backtracking
  • "Top K elements" → Heap
  • "Prefix matching" → Trie
  • "Next greater/smaller" → Monotonic Stack
  • "Matching pairs" → Stack
  • "Window of unique elements" → Sliding Window + Hash Set

šŸ“Š Complexity Cheat Sheet

Common Time Complexities (from best to worst):

  • O(1) - Constant
  • O(log n) - Logarithmic (Binary Search, Balanced Tree operations)
  • O(n) - Linear (Array traversal, Hash Table lookup)
  • O(n log n) - Linearithmic (Efficient sorting, Heap operations on n items)
  • O(n²) - Quadratic (Nested loops)
  • O(2ⁿ) - Exponential (Recursive branching without memoization)
  • O(n!) - Factorial (Permutations)

Space Complexity Considerations:

  • Recursion depth contributes to space complexity
  • Hash maps trade space for time
  • In-place algorithms are space-optimal but may be harder to implement

šŸ”‘ Key Interview Tips

  1. Clarify the problem - Ask about edge cases, constraints, input format
  2. Think out loud - Communicate your thought process
  3. Start with brute force - Then optimize
  4. Consider time-space tradeoffs - Sometimes using more space gives better time
  5. Test with examples - Walk through your solution with test cases
  6. Discuss edge cases - Empty input, single element, duplicates, etc.
  7. Know your complexities - Always analyze time and space complexity

šŸ“ˆ Progress Tracking

Total Problems: 70+ (with detailed solutions and explanations)

Suggested completion order:

  1. āœ“ Complete all Array, Two Pointers, Binary Search (Foundation)
  2. āœ“ Master Binary Tree and Stack/Queue (Essential data structures)
  3. āœ“ Practice Graph problems (Common in interviews)
  4. āœ“ Tackle Dynamic Programming (Most challenging)
  5. āœ“ Learn Backtracking patterns (Combination problems)
  6. āœ“ Understand Heap operations (Top K problems)
  7. āœ“ Review Trie, Greedy, Sorting (Specialized patterns)

šŸš€ Next Steps After This Crash Course

  1. Do more variations - Each pattern has 10-20 more problems on LeetCode
  2. Practice mock interviews - Use platforms like Pramp, interviewing.io
  3. Review company-specific patterns - Check Blind 75, Grind 75
  4. Build projects - Apply algorithms to real problems
  5. Contribute to discussions - Teach others to reinforce learning

šŸ“– Additional Resources


Remember: The goal isn't to memorize solutions, but to recognize patterns and understand the underlying principles. Happy coding! šŸŽ‰