DSA Notes
The definitive LeetCode guide — how to use LeetCode effectively, topic-wise problem lists, the 150-problem study plan, how to approach medium and hard problems, common patterns to master, time management in interviews, and which problems to prioritize by company.
What Is LeetCode?
LeetCode is the world's most popular platform for technical interview preparation. It hosts 3000+ algorithmic problems used by top tech companies including Google, Amazon, Meta, Microsoft, Apple, Bloomberg, Uber, LinkedIn, and hundreds more.
Unlike competitive programming platforms (Codeforces, AtCoder) which focus on algorithm knowledge, LeetCode focuses specifically on the type of problems that appear in software engineering interviews.
The LeetCode Grind — How to Actually Use It
Wrong Approach (What Most People Do)
Right Approach (Topic-Based Learning)
The Essential 150 — Problems You Must Know
Organized by topic in learning order:
Arrays and Hashing (10 problems)
| # | Problem | Difficulty | Pattern |
|---|---|---|---|
| 1 | Contains Duplicate | Easy | Hash set |
| 2 | Valid Anagram | Easy | Char count |
| 3 | Two Sum | Easy | Hash map |
| 4 | Group Anagrams | Medium | Key = sorted string |
| 5 | Top K Frequent Elements | Medium | Bucket sort / heap |
| 6 | Product of Array Except Self | Medium | Prefix/suffix |
| 7 | Valid Sudoku | Medium | Set per row/col/box |
| 8 | Encode/Decode Strings | Medium | Delimiter encoding |
| 9 | Longest Consecutive Sequence | Medium | Hash set |
| 10 | Sort Colors | Medium | Dutch National Flag |
Two Pointers (5 problems)
| # | Problem | Difficulty |
|---|---|---|
| 11 | Valid Palindrome | Easy |
| 12 | Two Sum II | Medium |
| 13 | 3Sum | Medium |
| 14 | Container With Most Water | Medium |
| 15 | Trapping Rain Water | Hard |
Sliding Window (6 problems)
| # | Problem | Difficulty |
|---|---|---|
| 16 | Best Time to Buy and Sell Stock | Easy |
| 17 | Longest Substring Without Repeating | Medium |
| 18 | Longest Repeating Character Replacement | Medium |
| 19 | Permutation In String | Medium |
| 20 | Minimum Window Substring | Hard |
| 21 | Sliding Window Maximum | Hard |
Binary Search (7 problems)
| # | Problem | Difficulty |
|---|---|---|
| 22 | Binary Search | Easy |
| 23 | Search a 2D Matrix | Medium |
| 24 | Koko Eating Bananas | Medium |
| 25 | Find Minimum in Rotated Sorted Array | Medium |
| 26 | Search in Rotated Sorted Array | Medium |
| 27 | Time Based Key-Value Store | Medium |
| 28 | Median of Two Sorted Arrays | Hard |
Trees (15 problems)
| # | Problem | Difficulty |
|---|---|---|
| 29 | Invert Binary Tree | Easy |
| 30 | Maximum Depth of Binary Tree | Easy |
| 31 | Diameter of Binary Tree | Easy |
| 32 | Balanced Binary Tree | Easy |
| 33 | Same Tree | Easy |
| 34 | Subtree of Another Tree | Easy |
| 35 | LCA of Binary Tree | Medium |
| 36 | Level Order Traversal | Medium |
| 37 | Right Side View | Medium |
| 38 | Count Good Nodes | Medium |
| 39 | Validate BST | Medium |
| 40 | Kth Smallest in BST | Medium |
| 41 | Construct Tree from Preorder+Inorder | Medium |
| 42 | Binary Tree Max Path Sum | Hard |
| 43 | Serialize/Deserialize Binary Tree | Hard |
The 14 Coding Patterns
Most LeetCode problems fall into 14 core patterns. Recognizing which pattern applies is the key skill:
Pattern 1 — Sliding Window
Trigger: "Contiguous subarray/substring with a condition"
Problems: Longest substring without repeat, minimum window substring, max sum subarray
Pattern 2 — Two Pointers
Trigger: "Sorted array, find pair/triplet with condition"
Pattern 3 — Fast/Slow Pointers
Trigger: "Linked list cycle detection, middle of list"
def has_cycle(head):
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast: return True
return FalsePattern 4 — Merge Intervals
Trigger: "Overlapping intervals, scheduling problems"
Pattern 5 — Binary Search on Answer
Trigger: "Find minimum/maximum feasible value"
def binary_search_answer(feasible_range, check_function):
lo, hi = feasible_range
while lo < hi:
mid = (lo + hi) // 2
if check_function(mid):
hi = mid # Try to do better
else:
lo = mid + 1
return loPattern 6 — BFS for Shortest Path
Trigger: "Minimum steps/moves in unweighted graph/grid"
Pattern 7 — DFS / Backtracking
Trigger: "All possible solutions, paths through a tree"
def dfs_backtrack(choices, current, result):
if is_complete(current):
result.append(list(current))
return
for choice in choices:
current.append(choice)
dfs_backtrack(remaining(choices, choice), current, result)
current.pop()Pattern 8 — Dynamic Programming (1D)
Trigger: "Optimal value at each position depends on previous"
Pattern 9 — Dynamic Programming (2D)
Trigger: "Paths in grid, string comparison problems"
Pattern 10 — Topological Sort
Trigger: "Course prerequisites, task scheduling with dependencies"
Pattern 11 — Union Find (DSU)
Trigger: "Connected components, cycle detection in undirected graph"
Pattern 12 — Trie
Trigger: "Prefix search, autocomplete, word existence queries"
Pattern 13 — Monotonic Stack
Trigger: "Next greater/smaller element, histogram problems"
Pattern 14 — Heap / Priority Queue
Trigger: "Kth largest/smallest, merge k sorted arrays"
Company-Specific Focus Areas
Favors: Graph algorithms, trees, system design, hard DP Must-know: BFS/DFS on grids, advanced binary search, segment trees
Amazon
Favors: Practical problems, OOP design, leadership principle stories Must-know: Trees (especially BST), graphs, DP, sliding window
Meta (Facebook)
Favors: Arrays, strings, trees, graphs Must-know: BFS, DFS, sliding window, two pointers, dynamic programming
Microsoft
Favors: Classic DS problems, clean code Must-know: Full breadth of easy-medium problems
Bloomberg
Favors: Real-world financial data structures, system design Must-know: Heaps, trees, graph algorithms
Time Management in Interviews
| 5 min | Understand the problem, ask clarifying questions |
| 5 min | Discuss approach, verify with interviewer |
| 25 min | Implement the solution |
| 5 min | Test on examples, find bugs |
| 5 min | Discuss optimizations, trade-offs |
Weekly Study Plan
| Monday | Arrays / Hash Maps (2 problems) |
| Tuesday | Trees (2 problems) |
| Wednesday | Graphs - BFS/DFS (2 problems) |
| Thursday | Dynamic Programming (2 problems) |
| Friday | Strings / Sliding Window (2 problems) |
| Saturday | Contest (LeetCode weekly contest) |
| Sunday | Review week's hard problems, read editorials |
Target: 14 problems/week = ~700 problems in a year
Summary
LeetCode mastery comes from:
- Topic-based learning — learn the algorithm, then practice it
- Pattern recognition — 14 patterns cover 80% of all problems
- Spaced repetition — revisit problems after 3 days, 1 week, 1 month
- Contest participation — weekly contests simulate interview pressure
- Company-specific practice — focus on patterns your target company favors
The goal is not to memorize solutions but to recognize patterns instantly and implement them cleanly under pressure.
*Next Lesson: Codeforces Guide*
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for LeetCode Guide — Complete Strategy to Crack FAANG Interviews.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Data Structures & Algorithms topic.
Search Terms
data-structures-algorithms, data structures & algorithms, data, structures, algorithms, competitive, programming, leetcode
Related Data Structures & Algorithms Topics