Skip to main content

Command Palette

Search for a command to run...

LeetCode Practice Roadmap — Pattern-Base

Published
4 min readView as Markdown
K

I am a developer who is highly interested in TypeScript. My tech stack has been full-stack TS such as Angular, React with TypeScript and NodeJS.

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.


  • 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.)

  1. Array + Hashing

    • 1 Two Sum, 242 Valid Anagram, 49 Group Anagrams, 347 Top K Frequent
  2. Sliding Window

    • 3 Longest Substring Without Repeating Characters

    • 567 Permutation in String, 438 Find All Anagrams, 76 Minimum Window Substring

  3. Prefix Sum / HashMap

    • 560 Subarray Sum Equals K, 525 Contiguous Array
  4. Two Pointers

    • 26 Remove Duplicates, 15 3Sum, 42 Trapping Rain Water
  5. 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)

  6. Stack / Monotonic

    • 20 Valid Parentheses, 739 Daily Temperatures, 84 Largest Rectangle in Histogram
  7. Linked List

    • 206 Reverse List, 21 Merge Two Lists, 2 Add Two Numbers, 141/142 Cycle I/II
  8. Tree & Graph (BFS/DFS)

    • 102 Level Order Traversal, 104 Max Depth, 226 Invert Tree

    • 200 Number of Islands, 207 Course Schedule

  9. Heap / Greedy

    • 215 Kth Largest, 23 Merge K Sorted Lists, 621 Task Scheduler
  10. 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)

  1. Read (5–7’): write the GOAL, input constraints, and edge cases (empty, duplicates, negatives, overflow, Unicode vs ASCII…).

  2. Plan (10–15’): choose a pattern; write the invariant (e.g., sliding window keeps window valid; BS maintains monotonic predicate).

  3. Code (15–25’): implement using your template.

  4. Test (5–10’): 5–8 custom cases (min/max, windows break, duplicates, all 9’s, etc.).

  5. 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 map of prefix → count, vars sum, count, res.

  • Binary Search: keep low, high, compute mid, 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

  1. carry = 0; dummy, tail = dummy

  2. loop while l1 || l2 || carry

  3. sum = (l1?.val||0) + (l2?.val||0) + carry

  4. push sum % 10; carry = Math.floor(sum / 10)

  5. advance l1, l2 → return dummy.next


2) Longest Substring Without Repeating Characters (#3)

  • Sliding window + last index (index+1).

  • For ASCII: Int32Array(128); if non‑ASCII, use for...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 A is 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 (decrease i); if Bleft > Aright → move right (increase i).

  • Median: if T odd → 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.

More from this blog

E

Essential programming concepts

54 posts

I'm a software engineer who is highly interested in TypeScript/ JavaScript. My tech stack has been full-stack TS such as React, Angular with TypeScript/JavaScript and NodeJS.