CrackFrontendCF
Resources
Practice
CrackFrontend

Your guide to mastering frontend interviews

Resources

LibraryPracticeDonate

Company

About UsContact

Legal

Privacy PolicyTerms of Service

Built with ❀️ by Tushar Khanna

CrackFrontendCF
Resources
Practice

🎯 2-Month DSA Plan for Working Professionals: FAANG Interview Preparation

Complete 8-week DSA roadmap for working professionals targeting FAANG-level interviews - 45-60 minutes daily with high pattern repetition and spaced learning.

Interview Importance: πŸ”΄ Critical β€” A structured 8-week plan designed for full-time professionals to achieve FAANG-level Medium problem confidence with just 45-60 minutes daily commitment. This comprehensive guide is specifically designed for working professionals who: Work full-time and can dedicate 45-60 minutes on weekdays and 2-3 hours on weekends Want to target FAANG or top-tier company interviews Need a structured, proven roadmap with high pattern repetition Aim to solve ~90 curated problems in 8 weeks with spaced repetition -- πŸ“‹ Table of Contents 1. Plan Overview 2. Core Principles & Rules 3. Week-by-Week Breakdown 4. Daily Structure 5. Progress Checkpoints 6. Pattern Recognition Framework 7. Common Interview Questions 8. Common Pitfalls 9. Time & Space Complexity Guide 10. Summary -- 1️⃣ Plan Overview Target Goal Why This Plan Works Traditional Approach Random 500problems 3-4 hours daily One-time solve Scattered None Real-World Analogy: Think of this like learning a musical instrument. You don't become a pianist by playing 500 different songs once. You master 20-30 pieces through deliberate practice, repetition, and pattern recognition. Similarly, these 90 problems teach you the 8 patterns that cover 80% of interview questions. -- 2️⃣ Core Principles & Rules (Non-Negotiable) Rule 1: No Problem Hopping Why this matters: Struggling builds problem-solving muscles Quick solution reading creates false confidence Re-solving cements the pattern Rule 2: Document Everything (2 Things Per Problem) For every problem solved, write: 1. Pattern Invariant (2 lines max) 2. Time Space Complexity Rule 3: Spaced Repetition Why this matters: Forgetting and re-learning strengthens neural pathways Prevents "I've seen this before but can't solve it" syndrome Builds true pattern recognition -- 3️⃣ Week-by-Week Breakdown Week 1: Arrays Two Pointers (Foundation) 🎯 Goal: Stop feeling "blank" when seeing array problems πŸ“Š Problem Distribution: 12 problems (8 Easy, 4 Medium) Problem Pattern Move Zeroes Two Pointers Remove Element Two Pointers Squares of a Sorted Array Two Pointers Two Sum HashMap Best Time to Buy and Sell Stock Single Pass Valid Palindrome Two Pointers Reverse String Two Pointers Merge Sorted Array Two Pointers Remove Duplicates from Sorted Array Two Pointers Container With Most Water Two Pointers Trapping Rain Water Two Pointers 3Sum Two Pointers Weekend Tasks: Two Pointers Template: -- Week 2: Sliding Window Hashing 🎯 Goal: Build "window thinking" automatically πŸ“Š Problem Distribution: 12 problems (4 Easy, 8 Medium) Problem Pattern Longest Substring Without Repeating Characters Sliding Window Minimum Size Subarray Sum Sliding Window Max Consecutive Ones III Sliding Window Permutation in String Sliding Window Find All Anagrams in a String Sliding Window Fruits Into Baskets Sliding Window Subarray Sum Equals K Prefix Sum HashMap Contains Duplicate HashMap Group Anagrams HashMap Top K Frequent Elements HashMap Bucket Valid Anagram HashMap Product of Array Except Self Prefix/Suffix Weekend Tasks: Sliding Window Checklist: -- Week 3: Stack Monotonic Stack 🎯 Goal: Handle "next greater/smaller" questions instinctively πŸ“Š Problem Distribution: 10 problems (3 Easy, 7 Medium) Problem Pattern Valid Parentheses Stack Min Stack Stack Daily Temperatures Monotonic Stack Next Greater Element I Monotonic Stack Next Greater Element II Monotonic Stack Evaluate Reverse Polish Notation Stack Largest Rectangle in Histogram Monotonic Stack Trapping Rain Water (Stack) Monotonic Stack Simplify Path Stack Remove All Adjacent Duplicates II Stack Weekend Tasks: Monotonic Stack Pattern: -- Week 4: Binary Search (Template Mastery) 🎯 Goal: Binary search should feel like a tool, not fear πŸ“Š Problem Distribution: 11 problems (5 Easy, 6 Medium) Problem Pattern Binary Search Binary Search Search Insert Position Binary Search Find First and Last Position Binary Search Search in Rotated Sorted Array Binary Search Find Minimum in Rotated Array Binary Search Peak Index in a Mountain Array Binary Search Koko Eating Bananas Answer Binary Search Capacity To Ship Packages Answer Binary Search Median of Two Sorted Arrays Binary Search Square Root (Integer) Binary Search Search a 2D Matrix Binary Search Weekend Tasks: Binary Search Templates: -- Week 5: Linked List Fast/Slow Pointers 🎯 Goal: Stop making pointer mistakes πŸ“Š Problem Distribution: 10 problems (6 Easy, 4 Medium) Problem Pattern Reverse Linked List Pointer Manipulation Merge Two Sorted Lists Two Pointers Linked List Cycle Fast/Slow Pointer Middle of the Linked List Fast/Slow Pointer Remove Nth Node From End Two Pointers Reorder List Multiple Patterns Intersection of Two Lists Two Pointers Add Two Numbers Linked List Palindrome Linked List Fast/Slow Reverse Copy List with Random Pointer HashMap Weekend Tasks: Linked List Patterns: -- Week 6: Trees (DFS/BFS Basics) 🎯 Goal: Recursion clarity traversal comfort πŸ“Š Problem Distribution: 12 problems (7 Easy, 5 Medium) Problem Pattern Maximum Depth of Binary Tree DFS Invert Binary Tree DFS Diameter of Binary Tree DFS Balanced Binary Tree DFS Same Tree DFS Subtree of Another Tree DFS Binary Tree Level Order BFS Validate Binary Search Tree DFS Lowest Common Ancestor BST BST Property Path Sum DFS Kth Smallest Element BST In-order DFS Construct Tree from Pre+In Recursion Weekend Tasks: Tree Traversal Patterns: -- Week 7: Heaps Greedy Intervals 🎯 Goal: Cover high-frequency interview patterns πŸ“Š Problem Distribution: 11 problems (2 Easy, 9 Medium) Problem Pattern 1 Medium LC 215 2 Medium LC 347 3 Hard LC 295 Intervals Merge Intervals Sorting Merge Insert Interval Linear Scan Non-overlapping Intervals Greedy Meeting Rooms II Heap 8 Medium LC 55 9 Medium LC 134 10 Medium LC 763 11 Medium LC 921 Difficulty LeetCode Graphs Number of Islands DFS/BFS Flood Fill DFS/BFS Clone Graph DFS HashMap Course Schedule Topological Sort Pacific Atlantic Water Flow DFS Rotting Oranges BFS 7 Easy LC 70 8 Medium LC 198 9 Medium LC 213 10 Medium LC 322 11 Medium LC 300 12 Medium LC 1143 Operation/Pattern Space Complexity Array traversal O(1) O(nΒ²) Find all pairs Binary search O(1) O(1) avg Two Sum Sorting O(1) or O(n) O(n) Palindrome check Sliding window O(k) O(n) Valid parentheses DFS/BFS tree O(h) or O(w) O(V E) Number of islands Heap operations O(n) O(n) to O(nΒ²) Coin change Week Problems Weekend Goal 1 12 Create template 2 12 Master window logic 3 10 Understand monotonic 4 11 2 templates ready 5 10 No pointer mistakes 6 12 DFS vs BFS clarity 7 11 Greedy intuition 8 12 mocks 2 mediums in 75 min | 5 Key Takeaways 1. Pattern Over Problems: Master 8 patterns, not 500 problems Each pattern covers 10-15 variations Spaced repetition makes patterns instinctive 2. Document Everything: Write pattern invariant complexity Forces you to understand "why" Builds pattern recognition muscle Makes review effortless 3. Spaced Repetition Works: Re-solve after 2 days and 7 days Forgetting β†’ Re-learning = Long-term memory Prevents "I've seen this but can't solve it" syndrome 4. Time Management: 45-60 mins daily is enough Consistency Marathon sessions Weekends for review mocks Working professionals can compete! 5. Interview Skills β‰  Problem Solving: Practice explaining Think out loud during mocks Explain complexity clearly Discuss trade-offs confidently Your Success Mantra -- πŸ“š Further Reading & Resources πŸŽ₯ Video Resources (YouTube) Pattern-Based Learning: NeetCode LeetCode Roadmap Complete playlist organized by patterns Abdul Bari Algorithms Deep dive into algorithm fundamentals TechDose DSA Series Visual explanations of patterns Inside Code DSA Clean animations for complex concepts Interview Preparation: ClΓ©ment Mihailescu AlgoExpert Interview tips and problem walkthroughs Back To Back SWE Detailed explanations with whiteboard sessions Kevin Naughton Jr. Live coding sessions Specific Patterns: Two Pointers & Sliding Window NeetCode Binary Search Template NeetCode Graph Algorithms William Fiset πŸ“– Essential Reading Algorithm Fundamentals: Introduction to Algorithms (CLRS) Comprehensive reference Cracking the Coding Interview Interview-focused problems Elements of Programming Interviews Advanced problem sets Online Articles & Guides: 14 Patterns to Ace Any Coding Interview Pattern recognition LeetCode Patterns by Sean Prashad Curated problem lists Two Pointer Technique GeeksforGeeks Sliding Window Technique AfterAcademy Interactive Learning: VisuAlgo Algorithm visualizations Algorithm Visualizer Interactive algorithm animations Big-O Cheat Sheet Complexity reference πŸ† Practice Platforms Primary Platforms: LeetCode Main practice platform (use Explore section for patterns) NeetCode.io Curated LeetCode roadmap with video solutions AlgoExpert Structured learning with video explanations (paid) Pattern-Focused Practice: LeetCode Patterns by Topic Blind 75 list Grind 75 Customizable practice plan Coding Patterns 16 pattern-based course (Grokking) Mock Interviews: Pramp Free peer-to-peer mock interviews Interviewing.io Anonymous practice with engineers LeetCode Mock Interview Timed company-specific mocks πŸ“Š Complexity Analysis Big O Notation Explained Time Complexity Analysis MIT OpenCourseWare Master Theorem Calculator For recursive complexity 🎯 Pattern-Specific Resources Two Pointers: Two Pointers Pattern LeetCode Discuss Sliding Window: Sliding Window Template LeetCode Discuss Binary Search: Binary Search 101 LeetCode Discuss Graph Algorithms: Graph Algorithms for Coding Interviews πŸ“± Mo
DSA
🎯 2-Month DSA Plan for Working Professionals: FAANG Interview Preparation
hard
🎯 30-Day DSA Mastery Guide for Senior Frontend Engineers
easy
🎯 Breadth-First Search (BFS): Level-Order Traversal Pattern for Frontend Interviews
hard
🎯 Depth-First Search (DFS): Deep Traversal Pattern for Frontend Interviews
hard
🎯 LRU & LFU Cache: Eviction Algorithms, Applications & Distributed Caching
hard
πŸ”€ Merge Two Sorted Arrays
hard
🎯 Prefix Sum Technique: Efficient Range Query Pattern for Frontend Interviews
hard
🎯 Sliding Window Technique: Efficient String & Array Pattern for Frontend Interviews
hard
🎯 Two-Pointer Technique: Essential Pattern for Frontend Interviews
hard
1 of 9
LibraryDSA1 of 9

🎯 2-Month DSA Plan for Working Professionals: FAANG Interview Preparation

dsahard

Interview Importance: πŸ”΄ Critical β€” A structured 8-week plan designed for full-time professionals to achieve FAANG-level Medium problem confidence with just 45-60 minutes daily commitment.

This comprehensive guide is specifically designed for working professionals who:

  • Work full-time and can dedicate 45-60 minutes on weekdays and 2-3 hours on weekends
  • Want to target FAANG or top-tier company interviews
  • Need a structured, proven roadmap with high pattern repetition
  • Aim to solve ~90 curated problems in 8 weeks with spaced repetition

πŸ“‹ Table of Contents

  1. Plan Overview
  2. Core Principles & Rules
  3. Week-by-Week Breakdown
  4. Daily Structure
  5. Progress Checkpoints
  6. Pattern Recognition Framework
  7. Common Interview Questions
  8. Common Pitfalls
  9. Time & Space Complexity Guide
  10. Summary

1️⃣ Plan Overview

Target Goal

Timeline:  8 weeks (2 months)
Target:    FAANG-level Medium confidence
Volume:    ~90 problems (curated, not random)
Time:      45-60 mins/day (Mon-Fri) + 2-3 hrs (Sat/Sun)
Focus:     High pattern repetition + spaced learning
Success:   Solve 2 mediums in 75 minutes reliably

Why This Plan Works

AspectTraditional ApproachThis Plan
Problem SelectionRandom 500+ problems90 curated with pattern focus
Time Investment3-4 hours daily45-60 mins weekdays, realistic for working professionals
Learning MethodOne-time solveSpaced repetition (2 days + 7 days)
Pattern CoverageScattered8 core patterns mastered deeply
Progress TrackingNoneWeekly checkpoints with clear metrics

Real-World Analogy:

Think of this like learning a musical instrument. You don't become a pianist by playing 500 different songs once. You master 20-30 pieces through deliberate practice, repetition, and pattern recognition. Similarly, these 90 problems teach you the 8 patterns that cover 80% of interview questions.


2️⃣ Core Principles & Rules (Non-Negotiable)

Rule 1: No Problem Hopping

Time Investment Per Problem:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 25-35 min: Genuine attempt (even if stuck) β”‚
β”‚ 10-15 min: Study solution + understand     β”‚
β”‚ 20-30 min: Re-solve without help          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Total: ~60 minutes per problem

Why this matters:

  • Struggling builds problem-solving muscles
  • Quick solution reading creates false confidence
  • Re-solving cements the pattern

Rule 2: Document Everything (2 Things Per Problem)

For every problem solved, write:

1. Pattern + Invariant (2 lines max)

// Example: Two Sum
Pattern: HashMap for O(1) lookup
Invariant: complement = target - current always exists in map when solution exists

2. Time + Space Complexity

// Time: O(n) - single pass through array
// Space: O(n) - hashmap stores up to n elements

Rule 3: Spaced Repetition

Day 1:  Solve problem for first time
Day 3:  Re-solve (2-day gap) ← Critical!
Day 8:  Re-solve (7-day gap) ← Mastery!

Why this matters:

  • Forgetting and re-learning strengthens neural pathways
  • Prevents "I've seen this before but can't solve it" syndrome
  • Builds true pattern recognition

3️⃣ Week-by-Week Breakdown

Week 1: Arrays + Two Pointers (Foundation)

🎯 Goal: Stop feeling "blank" when seeing array problems

πŸ“Š Problem Distribution: 12 problems (8 Easy, 4 Medium)

#ProblemDifficultyPatternLeetCode
1Move ZeroesEasyTwo PointersLC 283
2Remove ElementEasyTwo PointersLC 27
3Squares of a Sorted ArrayEasyTwo PointersLC 977
4Two SumEasyHashMapLC 1
5Best Time to Buy and Sell StockEasySingle PassLC 121
6Valid PalindromeEasyTwo PointersLC 125
7Reverse StringEasyTwo PointersLC 344
8Merge Sorted ArrayEasyTwo PointersLC 88
9Remove Duplicates from Sorted ArrayEasyTwo PointersLC 26
10Container With Most WaterMediumTwo PointersLC 11
11Trapping Rain WaterMediumTwo PointersLC 42
123SumMediumTwo PointersLC 15

Weekend Tasks:

βœ“ Re-solve: Move Zeroes, Remove Element, Container With Most Water
βœ“ Create your "Two Pointers Template"
βœ“ Write down: "When do I use two pointers?"

Two Pointers Template:

// Pattern 1: Opposite Direction (Converging)
const twoPointerConverge = (arr) => {
  let left = 0;
  let right = arr.length - 1;
  
  while (left < right) {
    // Process arr[left] and arr[right]
    // Move pointers based on condition
    if (condition) left++;
    else right--;
  }
};

// Pattern 2: Same Direction (Fast-Slow)
const twoPointerSameDir = (arr) => {
  let slow = 0;
  
  for (let fast = 0; fast < arr.length; fast++) {
    if (shouldKeep(arr[fast])) {
      arr[slow] = arr[fast];
      slow++;
    }
  }
  
  return slow; // New length
};

Week 2: Sliding Window + Hashing

🎯 Goal: Build "window thinking" automatically

πŸ“Š Problem Distribution: 12 problems (4 Easy, 8 Medium)

#ProblemDifficultyPatternLeetCode
1Longest Substring Without Repeating CharactersMediumSliding WindowLC 3
2Minimum Size Subarray SumMediumSliding WindowLC 209
3Max Consecutive Ones IIIMediumSliding WindowLC 1004
4Permutation in StringMediumSliding WindowLC 567
5Find All Anagrams in a StringMediumSliding WindowLC 438
6Fruits Into BasketsMediumSliding WindowLC 904
7Subarray Sum Equals KMediumPrefix Sum + HashMapLC 560
8Contains DuplicateEasyHashMapLC 217
9Group AnagramsMediumHashMapLC 49
10Top K Frequent ElementsMediumHashMap + BucketLC 347
11Valid AnagramEasyHashMapLC 242
12Product of Array Except SelfMediumPrefix/SuffixLC 238

Weekend Tasks:

βœ“ Re-solve: Longest Substring (#1), Permutation in String (#4), Subarray Sum (#7)
βœ“ Create "Sliding Window Checklist"
βœ“ Write down: "Fixed vs Variable window - when to use?"

Sliding Window Checklist:

// Variable-size window template
const slidingWindowVariable = (arr, target) => {
  let left = 0;
  let windowSum = 0;
  let result = 0;
  
  for (let right = 0; right < arr.length; right++) {
    // 1. Expand window (add arr[right])
    windowSum += arr[right];
    
    // 2. Shrink window while condition invalid
    while (windowSum > target) {
      windowSum -= arr[left];
      left++;
    }
    
    // 3. Update result
    result = Math.max(result, right - left + 1);
  }
  
  return result;
};

// Fixed-size window template
const slidingWindowFixed = (arr, k) => {
  let windowSum = 0;
  
  // Initialize first window
  for (let i = 0; i < k; i++) {
    windowSum += arr[i];
  }
  
  let maxSum = windowSum;
  
  // Slide window
  for (let i = k; i < arr.length; i++) {
    windowSum += arr[i] - arr[i - k]; // Add new, remove old
    maxSum = Math.max(maxSum, windowSum);
  }
  
  return maxSum;
};

Week 3: Stack + Monotonic Stack

🎯 Goal: Handle "next greater/smaller" questions instinctively

πŸ“Š Problem Distribution: 10 problems (3 Easy, 7 Medium)

#ProblemDifficultyPatternLeetCode
1Valid ParenthesesEasyStackLC 20
2Min StackEasyStackLC 155
3Daily TemperaturesMediumMonotonic StackLC 739
4Next Greater Element IEasyMonotonic StackLC 496
5Next Greater Element IIMediumMonotonic StackLC 503
6Evaluate Reverse Polish NotationMediumStackLC 150
7Largest Rectangle in HistogramHardMonotonic StackLC 84
8Trapping Rain Water (Stack)MediumMonotonic StackLC 42
9Simplify PathMediumStackLC 71
10Remove All Adjacent Duplicates IIMediumStackLC 1209

Weekend Tasks:

βœ“ Re-solve: Daily Temperatures, Largest Rectangle (understand, don't memorize)
βœ“ Write: "When to use stack? When to use monotonic stack?"

Monotonic Stack Pattern:

// Next Greater Element (Decreasing Stack)
const nextGreaterElement = (arr) => {
  const result = new Array(arr.length).fill(-1);
  const stack = []; // Store indices
  
  for (let i = 0; i < arr.length; i++) {
    // While current is greater than stack top
    while (stack.length > 0 && arr[i] > arr[stack[stack.length - 1]]) {
      const idx = stack.pop();
      result[idx] = arr[i]; // Found next greater for idx
    }
    stack.push(i);
  }
  
  return result;
};

// Pattern Recognition:
// "next greater" β†’ decreasing stack
// "next smaller" β†’ increasing stack

Week 4: Binary Search (Template Mastery)

🎯 Goal: Binary search should feel like a tool, not fear

πŸ“Š Problem Distribution: 11 problems (5 Easy, 6 Medium)

#ProblemDifficultyPatternLeetCode
1Binary SearchEasyBinary SearchLC 704
2Search Insert PositionEasyBinary SearchLC 35
3Find First and Last PositionMediumBinary SearchLC 34
4Search in Rotated Sorted ArrayMediumBinary SearchLC 33
5Find Minimum in Rotated ArrayMediumBinary SearchLC 153
6Peak Index in a Mountain ArrayEasyBinary SearchLC 852
7Koko Eating BananasMediumAnswer Binary SearchLC 875
8Capacity To Ship PackagesMediumAnswer Binary SearchLC 1011
9Median of Two Sorted ArraysHardBinary SearchLC 4
10Square Root (Integer)EasyBinary SearchLC 69
11Search a 2D MatrixMediumBinary SearchLC 74

Weekend Tasks:

βœ“ Create 2 templates:
  1. "Find exact element" template
  2. "Min feasible / Max feasible" (answer binary search) template
βœ“ Re-solve: Koko Eating Bananas, Capacity To Ship Packages

Binary Search Templates:

// Template 1: Find Exact Element
const binarySearchExact = (arr, target) => {
  let left = 0;
  let right = arr.length - 1;
  
  while (left <= right) {
    const mid = Math.floor(left + (right - left) / 2);
    
    if (arr[mid] === target) return mid;
    if (arr[mid] < target) left = mid + 1;
    else right = mid - 1;
  }
  
  return -1; // Not found
};

// Template 2: Answer Binary Search (Min Feasible)
const answerBinarySearch = (arr, condition) => {
  let left = minPossible;
  let right = maxPossible;
  let result = -1;
  
  while (left <= right) {
    const mid = Math.floor(left + (right - left) / 2);
    
    if (isFeasible(mid)) {
      result = mid; // Record feasible answer
      right = mid - 1; // Try to find smaller
    } else {
      left = mid + 1; // Need larger value
    }
  }
  
  return result;
};

// Pattern: "minimum days/speed/capacity" β†’ Answer Binary Search

Week 5: Linked List + Fast/Slow Pointers

🎯 Goal: Stop making pointer mistakes

πŸ“Š Problem Distribution: 10 problems (6 Easy, 4 Medium)

#ProblemDifficultyPatternLeetCode
1Reverse Linked ListEasyPointer ManipulationLC 206
2Merge Two Sorted ListsEasyTwo PointersLC 21
3Linked List CycleEasyFast/Slow PointerLC 141
4Middle of the Linked ListEasyFast/Slow PointerLC 876
5Remove Nth Node From EndMediumTwo PointersLC 19
6Reorder ListMediumMultiple PatternsLC 143
7Intersection of Two ListsEasyTwo PointersLC 160
8Add Two NumbersMediumLinked ListLC 2
9Palindrome Linked ListEasyFast/Slow + ReverseLC 234
10Copy List with Random PointerMediumHashMapLC 138

Weekend Tasks:

βœ“ Re-solve: Reverse LL, Remove Nth Node, Reorder List
βœ“ Master: "Why dummy node?" and "When fast/slow?"

Linked List Patterns:

// Pattern 1: Reverse Linked List
const reverseList = (head) => {
  let prev = null;
  let curr = head;
  
  while (curr) {
    const next = curr.next; // Save next
    curr.next = prev;       // Reverse pointer
    prev = curr;            // Move prev
    curr = next;            // Move curr
  }
  
  return prev; // New head
};

// Pattern 2: Fast/Slow Pointer (Find Middle)
const findMiddle = (head) => {
  let slow = head;
  let fast = head;
  
  while (fast && fast.next) {
    slow = slow.next;       // Move 1 step
    fast = fast.next.next;  // Move 2 steps
  }
  
  return slow; // Middle node
};

// Pattern 3: Dummy Node (Avoid Edge Cases)
const mergeLists = (l1, l2) => {
  const dummy = new ListNode(0);
  let curr = dummy;
  
  while (l1 && l2) {
    if (l1.val < l2.val) {
      curr.next = l1;
      l1 = l1.next;
    } else {
      curr.next = l2;
      l2 = l2.next;
    }
    curr = curr.next;
  }
  
  curr.next = l1 || l2;
  return dummy.next; // Skip dummy
};

Week 6: Trees (DFS/BFS Basics)

🎯 Goal: Recursion clarity + traversal comfort

πŸ“Š Problem Distribution: 12 problems (7 Easy, 5 Medium)

#ProblemDifficultyPatternLeetCode
1Maximum Depth of Binary TreeEasyDFSLC 104
2Invert Binary TreeEasyDFSLC 226
3Diameter of Binary TreeEasyDFSLC 543
4Balanced Binary TreeEasyDFSLC 110
5Same TreeEasyDFSLC 100
6Subtree of Another TreeEasyDFSLC 572
7Binary Tree Level OrderMediumBFSLC 102
8Validate Binary Search TreeMediumDFSLC 98
9Lowest Common Ancestor BSTEasyBST PropertyLC 235
10Path SumEasyDFSLC 112
11Kth Smallest Element BSTMediumIn-order DFSLC 230
12Construct Tree from Pre+InMediumRecursionLC 105

Weekend Tasks:

βœ“ Re-solve: Level Order, Validate BST, Diameter
βœ“ Master: DFS vs BFS decision making

Tree Traversal Patterns:

// Pattern 1: DFS Recursion (Most Common)
const maxDepth = (root) => {
  if (!root) return 0; // Base case
  
  const left = maxDepth(root.left);
  const right = maxDepth(root.right);
  
  return Math.max(left, right) + 1;
};

// Pattern 2: BFS (Level Order)
const levelOrder = (root) => {
  if (!root) return [];
  
  const result = [];
  const queue = [root];
  
  while (queue.length > 0) {
    const levelSize = queue.length;
    const currentLevel = [];
    
    for (let i = 0; i < levelSize; i++) {
      const node = queue.shift();
      currentLevel.push(node.val);
      
      if (node.left) queue.push(node.left);
      if (node.right) queue.push(node.right);
    }
    
    result.push(currentLevel);
  }
  
  return result;
};

// Pattern 3: BST Validation (Range Check)
const isValidBST = (root, min = -Infinity, max = Infinity) => {
  if (!root) return true;
  
  if (root.val <= min || root.val >= max) return false;
  
  return isValidBST(root.left, min, root.val) &&
         isValidBST(root.right, root.val, max);
};

// Decision: DFS when you need depth/paths, BFS when you need levels

Week 7: Heaps + Greedy + Intervals

🎯 Goal: Cover high-frequency interview patterns

πŸ“Š Problem Distribution: 11 problems (2 Easy, 9 Medium)

#ProblemDifficultyPatternLeetCode
Heaps
1Kth Largest Element in ArrayMediumHeap/QuickSelectLC 215
2Top K Frequent ElementsMediumHeap + HashMapLC 347
3Find Median from Data StreamHardTwo HeapsLC 295
Intervals
4Merge IntervalsMediumSorting + MergeLC 56
5Insert IntervalMediumLinear ScanLC 57
6Non-overlapping IntervalsMediumGreedyLC 435
7Meeting Rooms IIMediumHeapLC 253 (Premium)
Greedy
8Jump GameMediumGreedyLC 55
9Gas StationMediumGreedyLC 134
10Partition LabelsMediumGreedyLC 763
11Min Add Parentheses ValidMediumGreedyLC 921

Weekend Tasks:

βœ“ Re-solve: Merge Intervals, Meeting Rooms, Kth Largest
βœ“ Master: "When is greedy optimal?"

Key Patterns:

// Pattern 1: Merge Intervals
const mergeIntervals = (intervals) => {
  intervals.sort((a, b) => a[0] - b[0]);
  const result = [intervals[0]];
  
  for (let i = 1; i < intervals.length; i++) {
    const last = result[result.length - 1];
    
    if (intervals[i][0] <= last[1]) {
      // Overlapping: merge
      last[1] = Math.max(last[1], intervals[i][1]);
    } else {
      // Non-overlapping: add new
      result.push(intervals[i]);
    }
  }
  
  return result;
};

// Pattern 2: Min Heap (Using array for simplicity)
class MinHeap {
  constructor() {
    this.heap = [];
  }
  
  push(val) {
    this.heap.push(val);
    this.bubbleUp();
  }
  
  pop() {
    if (this.heap.length === 0) return null;
    
    const min = this.heap[0];
    const last = this.heap.pop();
    
    if (this.heap.length > 0) {
      this.heap[0] = last;
      this.bubbleDown();
    }
    
    return min;
  }
  
  peek() {
    return this.heap[0];
  }
  
  size() {
    return this.heap.length;
  }
  
  bubbleUp() {
    let idx = this.heap.length - 1;
    
    while (idx > 0) {
      const parentIdx = Math.floor((idx - 1) / 2);
      
      if (this.heap[idx] >= this.heap[parentIdx]) break;
      
      [this.heap[idx], this.heap[parentIdx]] = 
        [this.heap[parentIdx], this.heap[idx]];
      idx = parentIdx;
    }
  }
  
  bubbleDown() {
    let idx = 0;
    
    while (true) {
      const leftIdx = 2 * idx + 1;
      const rightIdx = 2 * idx + 2;
      let smallest = idx;
      
      if (leftIdx < this.heap.length && 
          this.heap[leftIdx] < this.heap[smallest]) {
        smallest = leftIdx;
      }
      
      if (rightIdx < this.heap.length && 
          this.heap[rightIdx] < this.heap[smallest]) {
        smallest = rightIdx;
      }
      
      if (smallest === idx) break;
      
      [this.heap[idx], this.heap[smallest]] = 
        [this.heap[smallest], this.heap[idx]];
      idx = smallest;
    }
  }
}

// Greedy Pattern: "Can we make local optimal choice?"
// If yes β†’ Greedy works
// If no β†’ Need DP

Week 8: Graphs + DP Intro + Mock Interviews

🎯 Goal: Convert knowledge into interview performance

πŸ“Š Problem Distribution: 12 problems + 2 mock interviews

#ProblemDifficultyPatternLeetCode
Graphs
1Number of IslandsMediumDFS/BFSLC 200
2Flood FillEasyDFS/BFSLC 733
3Clone GraphMediumDFS + HashMapLC 133
4Course ScheduleMediumTopological SortLC 207
5Pacific Atlantic Water FlowMediumDFSLC 417
6Rotting OrangesMediumBFSLC 994
DP Intro
7Climbing StairsEasyDPLC 70
8House RobberMediumDPLC 198
9House Robber IIMediumDPLC 213
10Coin ChangeMediumDPLC 322
11Longest Increasing SubseqMediumDPLC 300
12Longest Common SubseqMediumDPLC 1143

Mock Interviews (Critical!):

Mock 1: 1 Easy + 1 Medium (60 minutes)
  - Simulate real interview: talk out loud
  - Use timer: 25 min Easy, 35 min Medium
  - Practice: "Let me think through this..."

Mock 2: 1 Medium Deep-Dive (60 minutes)
  - 45 min: Solve medium problem
  - 15 min: Explain solution + optimizations
  - Practice: Complexity analysis explanation

Graph Patterns:

// Pattern 1: DFS on Grid
const numIslands = (grid) => {
  if (!grid.length) return 0;
  
  let count = 0;
  
  const dfs = (i, j) => {
    if (i < 0 || i >= grid.length || 
        j < 0 || j >= grid[0].length || 
        grid[i][j] === '0') {
      return;
    }
    
    grid[i][j] = '0'; // Mark visited
    
    dfs(i + 1, j);
    dfs(i - 1, j);
    dfs(i, j + 1);
    dfs(i, j - 1);
  };
  
  for (let i = 0; i < grid.length; i++) {
    for (let j = 0; j < grid[0].length; j++) {
      if (grid[i][j] === '1') {
        count++;
        dfs(i, j);
      }
    }
  }
  
  return count;
};

// Pattern 2: Simple DP (Climbing Stairs)
const climbStairs = (n) => {
  if (n <= 2) return n;
  
  let prev2 = 1; // dp[i-2]
  let prev1 = 2; // dp[i-1]
  
  for (let i = 3; i <= n; i++) {
    const curr = prev1 + prev2;
    prev2 = prev1;
    prev1 = curr;
  }
  
  return prev1;
};

// DP Pattern Recognition:
// "count ways" β†’ DP
// "minimum/maximum" + "all possibilities" β†’ DP
// Can we break into subproblems? β†’ DP

4️⃣ Daily Structure (45-60 Min)

Monday - Friday Routine

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 5 min:  Recall Yesterday's Pattern                 β”‚
β”‚         - What was the pattern?                     β”‚
β”‚         - What was the key insight?                 β”‚
β”‚         - Write 1-line summary                      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 25-35 min: Solve Today's Problem                   β”‚
β”‚         - Read problem carefully                    β”‚
β”‚         - Identify pattern                          β”‚
β”‚         - Attempt solution (25-35 min max)          β”‚
β”‚         - If stuck at 25 min β†’ Look at solution    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 10-15 min: Write Clean Solution + Document         β”‚
β”‚         - Write clean code                          β”‚
β”‚         - Dry run with example                      β”‚
β”‚         - Document: Pattern + Invariant             β”‚
β”‚         - Document: Time + Space complexity         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Example Daily Log:

// Day 12: Longest Substring Without Repeating Characters
// Pattern: Sliding Window (variable size)
// Invariant: window contains no duplicates (hashset tracks)
// Time: O(n) - each char visited at most twice
// Space: O(min(n, m)) - m = charset size

// Key Insight: Expand right, shrink left when duplicate found
// Mistake I made: Forgot to remove left char from set when shrinking

Saturday/Sunday Routine (2-3 hours)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 60-90 min: Re-solve 3 Problems (No Help!)         β”‚
β”‚         - Pick from 2 days ago and 7 days ago      β”‚
β”‚         - Set timer: 25 min each                   β”‚
β”‚         - NO peeking at solutions                  β”‚
β”‚         - If stuck: try 5 more min, then peek      β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 45-60 min: 1 Timed Session                        β”‚
β”‚         - Fresh medium problem                      β”‚
β”‚         - 35 min timer                             β”‚
β”‚         - Talk out loud (practice interviewing)    β”‚
β”‚         - Record: what slowed you down?            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 30-45 min: Pattern Notes Review                   β”‚
β”‚         - Review week's patterns                   β”‚
β”‚         - Identify weak spots                      β”‚
β”‚         - Write: "When to use X vs Y?"            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

5️⃣ Progress Checkpoints

🎯 End of Week 2 Checkpoint

You should be able to:

  • Solve most Easy array problems in 15-20 minutes
  • Identify "two pointers" vs "sliding window" pattern immediately
  • Explain why O(n) is better than O(nΒ²) with real examples

Self-Test:

Problem: "Find longest subarray with sum ≀ K"
Can you:
βœ“ Identify it's sliding window in 30 seconds?
βœ“ Write the template from memory?
βœ“ Solve in 20-25 minutes?

If No: Review Week 1-2 problems again


🎯 End of Week 4 Checkpoint

You should be able to:

  • Solve binary search problems with confidence
  • Distinguish "exact search" vs "answer search" instantly
  • Explain answer binary search to a friend

Self-Test:

Problem: "Minimum speed to finish tasks in D days"
Can you:
βœ“ Recognize it's answer binary search immediately?
βœ“ Define the search space (min, max)?
βœ“ Write isFeasible() function?
βœ“ Solve in 25 minutes?

If No: Redo Week 4 problems, focus on "why binary search works here"


🎯 End of Week 6 Checkpoint

You should be able to:

  • Trees no longer feel scary
  • Write DFS recursion without second-guessing
  • Explain DFS vs BFS trade-offs clearly

Self-Test:

Problem: "Find all paths that sum to target"
Can you:
βœ“ Choose DFS over BFS immediately?
βœ“ Write base case correctly?
βœ“ Handle backtracking if needed?
βœ“ Solve in 30 minutes?

If No: Redo tree problems, draw out recursion tree


🎯 End of Week 8 Checkpoint (Final Goal)

You should be able to:

  • Solve 2 mediums in 75 minutes reliably
  • Identify pattern within 2-3 minutes of reading problem
  • Explain your solution clearly during mock interview
  • Handle follow-up optimization questions

Final Self-Test:

Pick 2 random medium problems you haven't solved:
βœ“ Solve both in 75 minutes (no help)
βœ“ Write clean, bug-free code
βœ“ Explain time/space complexity
βœ“ Discuss alternative approaches

Success Rate Target: 80%+ (8 out of 10 attempts)

6️⃣ Pattern Recognition Framework

The 3-Line Output (Your Secret Weapon)

For every problem, force yourself to write this:

// 1. Pattern: [name of pattern]
// 2. Invariant: [what remains true throughout]
// 3. Why O(n): [why this complexity]

Example 1: Two Sum

// 1. Pattern: HashMap for O(1) lookup
// 2. Invariant: complement = target - current exists in map when solution found
// 3. Why O(n): Single pass, each lookup/insert is O(1)

Example 2: Longest Substring Without Repeating

// 1. Pattern: Sliding window (variable size) + HashSet
// 2. Invariant: window [left, right] contains no duplicates
// 3. Why O(n): Each character added once (right++) and removed once (left++)

Example 3: Valid Parentheses

// 1. Pattern: Stack for matching pairs
// 2. Invariant: Stack always contains unmatched opening brackets
// 3. Why O(n): Single pass, each push/pop is O(1)

Pattern Decision Tree

Problem Given
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Is it about array/string traversal?    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β†’ Finding pair/triplet?                β”‚
β”‚   β†’ Two Pointers (opposite direction)  β”‚
β”‚                                         β”‚
β”‚ β†’ Contiguous subarray with condition?  β”‚
β”‚   β†’ Sliding Window                     β”‚
β”‚                                         β”‚
β”‚ β†’ Need to track something for O(1)?   β”‚
β”‚   β†’ HashMap/HashSet                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Is it about finding next greater/      β”‚
β”‚ smaller or matching pairs?              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β†’ Next greater/smaller element?        β”‚
β”‚   β†’ Monotonic Stack                    β”‚
β”‚                                         β”‚
β”‚ β†’ Matching/nesting structure?          β”‚
β”‚   β†’ Stack                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Is data sorted or can be sorted?       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β†’ Search in sorted array?              β”‚
β”‚   β†’ Binary Search                      β”‚
β”‚                                         β”‚
β”‚ β†’ "Minimum X to achieve Y"?            β”‚
β”‚   β†’ Answer Binary Search               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Is it about linked list?               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β†’ Find middle/cycle?                   β”‚
β”‚   β†’ Fast/Slow Pointer                  β”‚
β”‚                                         β”‚
β”‚ β†’ Reverse/merge?                       β”‚
β”‚   β†’ Pointer Manipulation               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Is it about tree/graph?                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β†’ Need depth/paths?                    β”‚
β”‚   β†’ DFS (Recursion)                    β”‚
β”‚                                         β”‚
β”‚ β†’ Need level-by-level?                β”‚
β”‚   β†’ BFS (Queue)                        β”‚
β”‚                                         β”‚
β”‚ β†’ Dependencies/cycles?                 β”‚
β”‚   β†’ Topological Sort                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚
     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Is it optimization problem?            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β†’ Can make local optimal choice?      β”‚
β”‚   β†’ Greedy                             β”‚
β”‚                                         β”‚
β”‚ β†’ Need to consider all possibilities?  β”‚
β”‚   β†’ Dynamic Programming                β”‚
β”‚                                         β”‚
β”‚ β†’ Need top K elements?                 β”‚
β”‚   β†’ Heap                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

7️⃣ Common Interview Questions

Q1: How do you approach a problem you've never seen before?

Model Answer:

1. Clarify the problem:
   - "Can I assume the array is sorted?"
   - "What should I return if input is empty?"
   - "Are there any constraints on input size?"

2. Start with brute force:
   - "The naive approach would be O(nΒ²) nested loops"
   - "But we can optimize using..."

3. Identify pattern:
   - "This looks like a two-pointer problem because..."
   - "I notice we need to track a window, so sliding window"

4. Explain as you code:
   - "I'm using a HashMap here because..."
   - "This edge case handles when..."

5. Test with examples:
   - Walk through with given example
   - Test edge case: empty, single element, duplicates

Q2: What's the difference between two pointers and sliding window?

Model Answer:

Two Pointers:
- Used when we need to compare/process two elements
- Pointers can move in opposite directions (converging)
- Or same direction with different speeds (fast/slow)
- Example: Palindrome check, remove duplicates

Sliding Window:
- Used for contiguous subarrays/substrings
- Window expands (right++) and shrinks (left++)
- Maintains some property within window
- Example: Longest substring, max sum subarray

Key Difference:
- Two pointers: Usually about element relationship
- Sliding window: Always about subarray/substring property

Q3: When should I use DFS vs BFS for trees?

Model Answer:

Use DFS when:
βœ“ You need to explore depth (all paths, max depth)
βœ“ You need to process nodes top-to-bottom
βœ“ Problem involves recursion naturally
βœ“ Space constraint (DFS uses O(h), BFS uses O(w))
Examples: Validate BST, Path Sum, Diameter

Use BFS when:
βœ“ You need level-by-level processing
βœ“ You need to find shortest path
βœ“ You need nodes at same level together
Examples: Level Order, Min Depth, Right Side View

Trade-off:
- DFS: O(h) space, harder to reason about levels
- BFS: O(w) space, easier for level-based problems

Q4: How do you know when to use a HashMap?

Model Answer:

Use HashMap when you need:
1. O(1) lookup/insertion
   - "Have I seen this element before?"
   - Two Sum: "Does complement exist?"

2. Frequency counting
   - Group Anagrams, Top K Frequent
   - Character count for anagram checking

3. Index tracking
   - "Where did I last see this character?"
   - Longest Substring Without Repeating

4. Mapping relationships
   - Clone Graph: original β†’ clone mapping
   - Isomorphic Strings: char β†’ char mapping

Pattern:
If you're writing nested loop to search β†’ Use HashMap

Q5: How do you handle time/space complexity questions?

Model Answer:

Time Complexity:
"Let me walk through what happens:
- We iterate through n elements once β†’ O(n)
- For each element, we do constant work β†’ O(1)
- Total: O(n) Γ— O(1) = O(n)"

Space Complexity:
"For space, we're using:
- HashMap that stores at most n elements β†’ O(n)
- A few variables (left, right) β†’ O(1)
- Total: O(n) for the HashMap"

Pro Tip:
Always mention:
1. What 'n' represents
2. Why each operation is O(?)
3. Whether you can optimize further

Q6: What do you do when you're stuck in an interview?

Model Answer:

1. Think out loud:
   "I'm thinking about using a HashMap here, but..."
   "Let me consider the edge cases first..."

2. Start with brute force:
   "I can solve this in O(nΒ²) by..."
   "But I think we can optimize to O(n) by..."

3. Ask for hints:
   "I'm stuck on handling duplicates. Can you give me a hint?"
   "Should I be thinking about sorting first?"

4. Work through an example:
   "Let me trace through with [1, 2, 3]..."
   "Oh, I see the pattern now!"

5. Discuss trade-offs:
   "I could use more space to optimize time..."
   "Which would you prefer in production?"

Remember: Interviewers care more about your thought process
than getting the perfect answer immediately.

8️⃣ Common Pitfalls to Avoid

Pitfall 1: Not Understanding the Problem

❌ BAD Approach:

// Jumped straight into coding without clarification
const solve = (arr) => {
  // Wait, is arr sorted? Can it be empty?
  // What if there are duplicates?
  for (let i = 0; i < arr.length; i++) {
    // I'm not even sure what I'm trying to find...
  }
};

βœ… GOOD Approach:

/**
 * Before coding, I clarified:
 * 1. Input: sorted array, can have duplicates
 * 2. Output: index of first occurrence
 * 3. Edge: return -1 if not found
 * 4. Constraints: O(log n) expected β†’ binary search
 */
const searchFirst = (arr, target) => {
  let left = 0;
  let right = arr.length - 1;
  let result = -1;
  
  while (left <= right) {
    const mid = Math.floor(left + (right - left) / 2);
    
    if (arr[mid] === target) {
      result = mid;      // Found, but keep searching left
      right = mid - 1;   // for first occurrence
    } else if (arr[mid] < target) {
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }
  
  return result;
};

What goes wrong: Solving the wrong problem, missing edge cases, inefficient approach.


Pitfall 2: Ignoring Edge Cases

❌ BAD Approach:

// Remove duplicates from sorted array
const removeDuplicates = (nums) => {
  let j = 0;
  
  for (let i = 1; i < nums.length; i++) {
    if (nums[i] !== nums[j]) {
      j++;
      nums[j] = nums[i];
    }
  }
  
  return j + 1;
  // BUG: What if nums is empty? nums.length = 0
  // j + 1 = 1, but should return 0!
};

βœ… GOOD Approach:

const removeDuplicates = (nums) => {
  // Handle edge case: empty array
  if (nums.length === 0) return 0;
  
  let j = 0;
  
  for (let i = 1; i < nums.length; i++) {
    if (nums[i] !== nums[j]) {
      j++;
      nums[j] = nums[i];
    }
  }
  
  return j + 1;
};

// Always test with:
// 1. Empty: []
// 2. Single element: [1]
// 3. All duplicates: [1, 1, 1]
// 4. No duplicates: [1, 2, 3]

What goes wrong: Runtime errors, wrong answers for edge cases, failed test cases.


Pitfall 3: Incorrect Loop Bounds

❌ BAD Approach:

// Find pairs with sum = target (two pointers)
const twoSum = (arr, target) => {
  let left = 0;
  let right = arr.length - 1;
  
  // BUG: Should be left < right, not left <= right
  while (left <= right) {
    const sum = arr[left] + arr[right];
    
    if (sum === target) {
      return [left, right];
    } else if (sum < target) {
      left++;
    } else {
      right--;
    }
  }
  
  return null;
};

// When left === right, we're using same element twice!
// Example: arr = [2, 3], target = 4
// When left = 0, right = 0 β†’ arr[0] + arr[0] = 4 βœ— Wrong!

βœ… GOOD Approach:

const twoSum = (arr, target) => {
  let left = 0;
  let right = arr.length - 1;
  
  while (left < right) { // βœ“ Correct: ensures different elements
    const sum = arr[left] + arr[right];
    
    if (sum === target) {
      return [left, right];
    } else if (sum < target) {
      left++;
    } else {
      right--;
    }
  }
  
  return null;
};

What goes wrong: Infinite loops, using same element twice, missing valid pairs.


Pitfall 4: Not Considering Integer Overflow

❌ BAD Approach:

// Binary search with overflow risk
const binarySearch = (arr, target) => {
  let left = 0;
  let right = arr.length - 1;
  
  while (left <= right) {
    // BUG: left + right can overflow for large values
    const mid = Math.floor((left + right) / 2);
    
    if (arr[mid] === target) return mid;
    if (arr[mid] < target) left = mid + 1;
    else right = mid - 1;
  }
  
  return -1;
};

βœ… GOOD Approach:

const binarySearch = (arr, target) => {
  let left = 0;
  let right = arr.length - 1;
  
  while (left <= right) {
    // βœ“ Safe from overflow
    const mid = Math.floor(left + (right - left) / 2);
    
    if (arr[mid] === target) return mid;
    if (arr[mid] < target) left = mid + 1;
    else right = mid - 1;
  }
  
  return -1;
};

// Why: (left + right) can overflow if left and right are large
// But: left + (right - left) / 2 won't overflow

What goes wrong: In languages like Java/C++, overflow causes bugs. Good practice in JavaScript too.


9️⃣ Time & Space Complexity Guide

Quick Reference Table

Operation/PatternTime ComplexitySpace ComplexityExample
Array traversalO(n)O(1)Single loop
Nested loopO(nΒ²)O(1)Find all pairs
Binary searchO(log n)O(1)Search sorted array
HashMap operationsO(1) avgO(n)Two Sum
SortingO(n log n)O(1) or O(n)Merge intervals
Two pointersO(n)O(1)Palindrome check
Sliding windowO(n)O(k)Longest substring
Stack operationsO(n)O(n)Valid parentheses
DFS/BFS treeO(n)O(h) or O(w)Tree traversal
DFS/BFS graphO(V + E)O(V)Number of islands
Heap operationsO(log n)O(n)Top K elements
Dynamic programmingO(n) to O(nΒ²)O(n) to O(nΒ²)Coin change

Complexity Analysis Examples

Example 1: Two Sum (HashMap)

const twoSum = (nums, target) => {
  const map = new Map(); // Space: O(n)
  
  for (let i = 0; i < nums.length; i++) { // Time: O(n)
    const complement = target - nums[i];
    
    if (map.has(complement)) { // O(1)
      return [map.get(complement), i];
    }
    
    map.set(nums[i], i); // O(1)
  }
  
  return null;
};

// Time: O(n) - single loop, O(1) operations inside
// Space: O(n) - hashmap stores at most n elements

Example 2: Sliding Window

const longestSubstring = (s) => {
  const seen = new Set(); // Space: O(min(n, m)) where m = charset size
  let left = 0;
  let maxLen = 0;
  
  for (let right = 0; right < s.length; right++) { // O(n)
    while (seen.has(s[right])) { // Inner loop: total O(n)
      seen.delete(s[left]);
      left++;
    }
    
    seen.add(s[right]);
    maxLen = Math.max(maxLen, right - left + 1);
  }
  
  return maxLen;
};

// Time: O(n) - each char visited at most twice (right++, left++)
// Space: O(min(n, m)) - set stores unique chars

Example 3: DFS Tree

const maxDepth = (root) => {
  if (!root) return 0; // Base case
  
  const left = maxDepth(root.left);   // Recursive
  const right = maxDepth(root.right); // Recursive
  
  return Math.max(left, right) + 1;
};

// Time: O(n) - visit each node once
// Space: O(h) - recursion stack, h = height
//        O(log n) for balanced tree
//        O(n) for skewed tree

πŸ”Ÿ Summary

Quick Reference: 8-Week Plan at a Glance

WeekFocusProblemsKey PatternsWeekend Goal
1Arrays + Two Pointers12Converging, Fast-slowCreate template
2Sliding Window + Hashing12Fixed/variable windowMaster window logic
3Stack + Monotonic Stack10Next greater/smallerUnderstand monotonic
4Binary Search11Exact + answer search2 templates ready
5Linked List10Fast/slow, reversalNo pointer mistakes
6Trees DFS/BFS12Recursion, level orderDFS vs BFS clarity
7Heaps + Greedy + Intervals11Top K, merge intervalsGreedy intuition
8Graphs + DP + Mocks12 + mocksDFS/BFS grid, basic DP2 mediums in 75 min

5 Key Takeaways

  1. Pattern Over Problems: Master 8 patterns, not 500 problems

    • Each pattern covers 10-15 variations
    • Spaced repetition makes patterns instinctive
  2. Document Everything: Write pattern + invariant + complexity

    • Forces you to understand "why"
    • Builds pattern recognition muscle
    • Makes review effortless
  3. Spaced Repetition Works: Re-solve after 2 days and 7 days

    • Forgetting β†’ Re-learning = Long-term memory
    • Prevents "I've seen this but can't solve it" syndrome
  4. Time Management: 45-60 mins daily is enough

    • Consistency > Marathon sessions
    • Weekends for review + mocks
    • Working professionals can compete!
  5. Interview Skills β‰  Problem Solving: Practice explaining

    • Think out loud during mocks
    • Explain complexity clearly
    • Discuss trade-offs confidently

Your Success Mantra

Progress Formula:
─────────────────────────────────────────────
  90 problems Γ— Spaced repetition
  Γ· 8 weeks
  = FAANG interview confidence
─────────────────────────────────────────────

Remember:
βœ“ You don't need to be perfect
βœ“ You don't need 500 problems
βœ“ You need patterns + practice + persistence

πŸ“š Further Reading & Resources

πŸŽ₯ Video Resources (YouTube)

Pattern-Based Learning:

  • NeetCode - LeetCode Roadmap - Complete playlist organized by patterns
  • Abdul Bari - Algorithms - Deep dive into algorithm fundamentals
  • TechDose - DSA Series - Visual explanations of patterns
  • Inside Code - DSA - Clean animations for complex concepts

Interview Preparation:

  • ClΓ©ment Mihailescu - AlgoExpert - Interview tips and problem walkthroughs
  • Back To Back SWE - Detailed explanations with whiteboard sessions
  • Kevin Naughton Jr. - Live coding sessions

Specific Patterns:

  • Two Pointers & Sliding Window - NeetCode
  • Binary Search Template - NeetCode
  • Graph Algorithms - William Fiset

πŸ“– Essential Reading

Algorithm Fundamentals:

  • Introduction to Algorithms (CLRS) - Comprehensive reference
  • Cracking the Coding Interview - Interview-focused problems
  • Elements of Programming Interviews - Advanced problem sets

Online Articles & Guides:

  • 14 Patterns to Ace Any Coding Interview - Pattern recognition
  • LeetCode Patterns by Sean Prashad - Curated problem lists
  • Two Pointer Technique - GeeksforGeeks
  • Sliding Window Technique - AfterAcademy

Interactive Learning:

  • VisuAlgo - Algorithm visualizations
  • Algorithm Visualizer - Interactive algorithm animations
  • Big-O Cheat Sheet - Complexity reference

πŸ† Practice Platforms

Primary Platforms:

  • LeetCode - Main practice platform (use Explore section for patterns)
  • NeetCode.io - Curated LeetCode roadmap with video solutions
  • AlgoExpert - Structured learning with video explanations (paid)

Pattern-Focused Practice:

  • LeetCode Patterns by Topic - Blind 75 list
  • Grind 75 - Customizable practice plan
  • Coding Patterns - 16 pattern-based course (Grokking)

Mock Interviews:

  • Pramp - Free peer-to-peer mock interviews
  • Interviewing.io - Anonymous practice with engineers
  • LeetCode Mock Interview - Timed company-specific mocks

πŸ“Š Complexity Analysis

  • Big O Notation Explained
  • Time Complexity Analysis - MIT OpenCourseWare
  • Master Theorem Calculator - For recursive complexity

🎯 Pattern-Specific Resources

Two Pointers:

  • Two Pointers Pattern - LeetCode Discuss

Sliding Window:

  • Sliding Window Template - LeetCode Discuss

Binary Search:

  • Binary Search 101 - LeetCode Discuss

Graph Algorithms:

  • Graph Algorithms for Coding Interviews

πŸ“± Mobile Apps

  • LeetCode Mobile - iOS/Android for on-the-go practice
  • Anki - Spaced repetition flashcards for patterns
  • Forest - Focus timer for Pomodoro technique

πŸ—“οΈ Study Tools

Tracking Progress:

  • LeetCode Progress Tracker (Notion) - Template for tracking
  • Spaced Repetition Calculator - SM-2 algorithm

Community:

  • r/leetcode - Reddit community
  • LeetCode Discuss - Official discussion forum
  • Blind - Interview experiences

πŸ“ Related Articles in This Repository

  • 30-Day DSA Guide for Senior Frontend Engineers
  • Two Pointer Technique
  • Sliding Window Pattern
  • DFS Deep Dive
  • BFS Complete Guide

πŸ’‘ Pro Tips for Using These Resources

  1. Start with NeetCode roadmap - Follow their curated list alongside this plan
  2. Watch videos at 1.5x speed - Save time while learning patterns
  3. Use VisuAlgo for visualization - Understand complex algorithms visually
  4. Join LeetCode discussions - Read solutions after solving
  5. Track with Notion/Excel - Monitor your spaced repetition schedule
  6. Use Anki for pattern flashcards - Reinforce pattern recognition
  7. Practice on Pramp weekly - Get comfortable explaining solutions

Quick Quiz

Test your understanding with 8 quick questions

Q1What is the primary advantage of the spaced repetition approach (re-solving after 2 days and 7 days)?
Q2For the problem "Find the minimum speed to finish all tasks within D days", which pattern should you use?
Q3When should you use a HashMap in problem-solving?
Q4What's the key difference between two pointers and sliding window patterns?
Q5By the end of Week 8, what should you reliably be able to do?
Q6What is the recommended time to attempt a problem before looking at the solution during weekdays?
Q7For tree problems, when should you use BFS instead of DFS?
Q8What does the "3-line output" framework require you to write for every problem?

Continue Reading

CrackFrontend

Your guide to mastering frontend interviews

Resources

LibraryPracticeDonate

Company

About UsContact

Legal

Privacy PolicyTerms of Service

Built with ❀️ by Tushar Khanna