LeetCode Practice Roadmap — Pattern-Base
High‑leverage way to level up fast: solve by patterns, review with spaced repetition, and mix in random problems.
Why not go from #1 → #N?
Cons: scattered knowledge, hard to spot patterns, slow retention, lots of near-duplicates.
Pros: easy to start.
Verdict: prefer pattern-based practice.
Recommended Strategy (70 / 20 / 10)
70% Pattern modules (6–10 problems/module), build reusable templates.
20% Mixed/Random to keep adaptability.
10% Review (spaced repetition) for problems you struggled with.
Spaced repetition: review on day 1 → day 3 → day 7 (or 1–2–4 if short on time).
Topic Order & Must‑Do Problems (sample)
(Numbers are LeetCode IDs; pick variants as needed.)
Array + Hashing
- 1 Two Sum, 242 Valid Anagram, 49 Group Anagrams, 347 Top K Frequent
Sliding Window
3 Longest Substring Without Repeating Characters
567 Permutation in String, 438 Find All Anagrams, 76 Minimum Window Substring
Prefix Sum / HashMap
- 560 Subarray Sum Equals K, 525 Contiguous Array
Two Pointers
- 26 Remove Duplicates, 15 3Sum, 42 Trapping Rain Water
Binary Search
704 Binary Search, 34 First/Last Position
33 Search in Rotated Array, 153 Find Min in Rotated Array
4 Median of Two Sorted Arrays (capstone for BS over indices/conditions)
Stack / Monotonic
- 20 Valid Parentheses, 739 Daily Temperatures, 84 Largest Rectangle in Histogram
Linked List
- 206 Reverse List, 21 Merge Two Lists, 2 Add Two Numbers, 141/142 Cycle I/II
Tree & Graph (BFS/DFS)
102 Level Order Traversal, 104 Max Depth, 226 Invert Tree
200 Number of Islands, 207 Course Schedule
Heap / Greedy
- 215 Kth Largest, 23 Merge K Sorted Lists, 621 Task Scheduler
Dynamic Programming (Fundamentals → Intermediate)
- 70 Climbing Stairs, 198 House Robber, 322 Coin Change, 300 LIS, 1143 LCS
Tip: You don’t have to follow the exact order within each module—keep difficulty progressive.
Per‑Problem Workflow (25–45 minutes)
Read (5–7’): write the GOAL, input constraints, and edge cases (empty, duplicates, negatives, overflow, Unicode vs ASCII…).
Plan (10–15’): choose a pattern; write the invariant (e.g., sliding window keeps window valid; BS maintains monotonic predicate).
Code (15–25’): implement using your template.
Test (5–10’): 5–8 custom cases (min/max, windows break, duplicates, all 9’s, etc.).
Post‑mortem (3’): if hints were needed, log why, the correct invariant, and your pitfalls.
Templates & Naming (JS‑centric)
Sliding Window (ASCII): prefer
Int32Array(128)+charCodeAt, store last index + 1. Vars:left,res,last.Prefix Sum: use
mapof prefix → count, varssum,count,res.Binary Search: keep
low,high, computemid, maintain a monotone predicate.Linked List: build with dummy head, return
dummy.next. Vars:tail,carry.
Quick Cheat Sheets (Core Problems)
1) Add Two Numbers (#2)
Add digit by digit with carry using a dummy head; return
dummy.next.Time: O(max(m,n)), Space: O(max(m,n)) for result list.
Steps
carry = 0;dummy,tail = dummyloop while
l1 || l2 || carrysum = (l1?.val||0) + (l2?.val||0) + carrypush
sum % 10;carry = Math.floor(sum / 10)advance
l1,l2→ returndummy.next
2) Longest Substring Without Repeating Characters (#3)
Sliding window + last index (index+1).
For ASCII:
Int32Array(128); if non‑ASCII, usefor...of+Map.
Core loop
prev = last[c];
left = Math.max(left, prev);
res = Math.max(res, i - left + 1);
last[c] = i + 1;
3) Median of Two Sorted Arrays (#4) — Partition
Assume
Ais the shorter array (m ≤ n),T = m+n,half = floor((T+1)/2).Binary search
i(# taken from A-left);j = half - i.
Check partition
Aleft = (i>0) ? A[i-1] : -∞
Aright = (i<m) ? A[i] : +∞
Bleft = (j>0) ? B[j-1] : -∞
Bright = (j<n) ? B[j] : +∞
valid if: Aleft ≤ Bright && Bleft ≤ Aright
If
Aleft > Bright→ move left (decreasei); ifBleft > Aright→ move right (increasei).Median: if
Todd →max(Aleft, Bleft); else →(max(Aleft,Bleft)+min(Aright,Bright))/2.
Weekly Sample Plan (2h/day)
Mon: Array+Hashing (4 probs) → review 2 old.
Tue: Sliding Window (3) → +1 random easy.
Wed: Prefix Sum (2) + Two Pointers (2).
Thu: Binary Search (3).
Fri: Stack/Monotonic (2) + Linked List (2).
Sat: Tree/Graph (3).
Sun: DP (2) + 1h mixed mock.
Review List Criteria
Add to review if:
took >25 minutes,
needed hints,
or had WA due to missed edge cases. Revisit on day 1, 3, 7. Re‑implement from a blank template.



