Based on analysis of FAANG+ interview patterns and Blind 75 questions
- Two Pointers
- Sliding Window
- Hash Map/Set
- Binary Search
- DFS/BFS
- Dynamic Programming
- Fast & Slow Pointers
- Merge Intervals
- Backtracking
- Heap/Priority Queue
- Stack/Queue
- Tree Traversals
- Topological Sort
- Union Find
- Bit Manipulation
- Greedy Algorithms
- Trie
- Segment Tree/Fenwick Tree
When to Use: Sorted arrays, palindromes, pair problems Time: O(n) | Space: O(1)
Common Problems:
- Two Sum (sorted array)
- 3Sum, 4Sum
- Container with Most Water
- Trapping Rain Water
- Valid Palindrome
Template:
function twoPointers(arr) {
let left = 0, right = arr.length - 1;
while (left < right) {
if (condition) {
// Process and move pointers
left++;
} else {
right--;
}
}
}Companies: Google ⭐⭐⭐, Meta ⭐⭐⭐, Amazon ⭐⭐⭐
When to Use: Contiguous subarrays/substrings, optimization problems Time: O(n) | Space: O(k)
Variations:
- Fixed Size: Maximum sum subarray of size K
- Variable Size: Longest substring without repeating characters
- Shrinking: Minimum window substring
Template:
function slidingWindow(arr) {
let left = 0, maxVal = 0;
for (let right = 0; right < arr.length; right++) {
// Expand window
while (windowConditionViolated) {
// Shrink window
left++;
}
maxVal = Math.max(maxVal, right - left + 1);
}
return maxVal;
}Companies: Microsoft ⭐⭐⭐, Amazon ⭐⭐⭐, Google ⭐⭐
When to Use: Frequency counting, lookups, duplicate detection Time: O(n) | Space: O(n)
Common Problems:
- Two Sum
- Group Anagrams
- Top K Frequent Elements
- Longest Consecutive Sequence
Template:
function hashMapPattern(arr) {
const map = new Map();
for (const item of arr) {
map.set(item, (map.get(item) || 0) + 1);
}
// Process map entries
}Companies: All companies ⭐⭐⭐⭐⭐
When to Use: Sorted arrays, search space reduction, optimization Time: O(log n) | Space: O(1)
Variations:
- Classic: Find target in sorted array
- Lower/Upper Bound: First/last occurrence
- Search in Rotated: Rotated sorted array
- Answer Search: Search for the answer
Template:
function binarySearch(arr, target) {
let left = 0, right = arr.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) return mid;
else if (arr[mid] < target) left = mid + 1;
else right = mid - 1;
}
return -1;
}Companies: Google ⭐⭐⭐⭐, Meta ⭐⭐⭐, Amazon ⭐⭐⭐
When to Use: Tree/graph traversal, shortest path, connected components Time: O(V + E) | Space: O(V)
DFS Template:
function dfs(node, visited) {
if (!node || visited.has(node)) return;
visited.add(node);
// Process current node
for (const neighbor of node.neighbors) {
dfs(neighbor, visited);
}
}BFS Template:
function bfs(start) {
const queue = [start];
const visited = new Set([start]);
while (queue.length) {
const node = queue.shift();
// Process current node
for (const neighbor of node.neighbors) {
if (!visited.has(neighbor)) {
visited.add(neighbor);
queue.push(neighbor);
}
}
}
}Companies: Meta ⭐⭐⭐⭐, Google ⭐⭐⭐⭐, Amazon ⭐⭐⭐
When to Use: Optimization, counting, decision problems with overlapping subproblems Time: Varies | Space: O(n) to O(n²)
Approaches:
- Top-down: Memoization (recursive)
- Bottom-up: Tabulation (iterative)
Template:
// Top-down (Memoization)
function dpTopDown(n, memo = new Map()) {
if (baseCase) return baseValue;
if (memo.has(n)) return memo.get(n);
const result = /* recurrence relation */;
memo.set(n, result);
return result;
}
// Bottom-up (Tabulation)
function dpBottomUp(n) {
const dp = new Array(n + 1);
dp[0] = baseValue;
for (let i = 1; i <= n; i++) {
dp[i] = /* recurrence relation */;
}
return dp[n];
}Companies: All companies ⭐⭐⭐⭐⭐
When to Use: Cycle detection, finding middle, palindrome checks Time: O(n) | Space: O(1)
Template:
function fastSlowPointers(head) {
let slow = head, fast = head;
while (fast && fast.next) {
slow = slow.next;
fast = fast.next.next;
if (slow === fast) {
// Cycle detected
return true;
}
}
return false;
}Companies: Microsoft ⭐⭐⭐, Amazon ⭐⭐⭐, Google ⭐⭐
When to Use: Overlapping intervals, scheduling problems Time: O(n log n) | Space: O(1)
Template:
function mergeIntervals(intervals) {
intervals.sort((a, b) => a[0] - b[0]);
const merged = [intervals[0]];
for (let i = 1; i < intervals.length; i++) {
const current = intervals[i];
const lastMerged = merged[merged.length - 1];
if (current[0] <= lastMerged[1]) {
lastMerged[1] = Math.max(lastMerged[1], current[1]);
} else {
merged.push(current);
}
}
return merged;
}Companies: Google ⭐⭐⭐, Amazon ⭐⭐⭐, Microsoft ⭐⭐
When to Use: Top K problems, merge operations, scheduling Time: O(n log k) | Space: O(k)
Template:
class MinHeap {
constructor() {
this.heap = [];
}
push(val) {
this.heap.push(val);
this.bubbleUp();
}
pop() {
if (this.heap.length === 1) return this.heap.pop();
const min = this.heap[0];
this.heap[0] = this.heap.pop();
this.bubbleDown();
return min;
}
}Companies: Amazon ⭐⭐⭐⭐, Google ⭐⭐⭐, Meta ⭐⭐
When to Use: Generating all solutions, permutations, combinations Time: O(2^n) to O(n!) | Space: O(n)
Template:
function backtrack(path, choices) {
if (isComplete(path)) {
result.push([...path]);
return;
}
for (const choice of choices) {
if (isValid(choice)) {
path.push(choice);
backtrack(path, getNewChoices(choice));
path.pop(); // backtrack
}
}
}Companies: Meta ⭐⭐⭐, Google ⭐⭐⭐, Amazon ⭐⭐
- Favorites: Binary Search, DFS/BFS, Dynamic Programming
- Focus: Complex algorithms, optimization
- Avoid: Brute force solutions
- Favorites: DFS/BFS, Backtracking, Hash Maps
- Focus: Social network problems, graph algorithms
- Specialty: Tree/graph traversals
- Favorites: Two Pointers, Heap, Sliding Window
- Focus: System design + algorithms
- Practical: Real-world optimization problems
- Favorites: Fast/Slow Pointers, Stack/Queue, Intervals
- Focus: Clean code, edge cases
- Balanced: Mix of all patterns
- Favorites: Arrays, Strings, Basic DS
- Focus: Implementation details
- Style: Elegant, efficient solutions
- Two Pointers (start here like your moveZeros problem!)
- Hash Maps/Sets
- Sliding Window
- Binary Search
- Fast & Slow Pointers
- Stack/Queue problems
- DFS/BFS
- Tree Traversals
- Graph basics
- Dynamic Programming (start with 1D)
- Backtracking
- Heap/Priority Queue
- Merge Intervals
- Topological Sort
- Union Find
- 30 min: Review pattern theory
- 60 min: Solve 2-3 problems
- 30 min: Analyze solutions, edge cases
- Start with Easy problems to build confidence
- Move to Medium after mastering the pattern
- Attempt Hard only after 80% Medium success rate
- LeetCode: Pattern-based problem lists
- NeetCode: Blind 75 with video explanations
- AlgoExpert: Comprehensive pattern coverage
- Grokking Coding Patterns: Structured learning
- Jumping patterns: Master one before moving to next
- Ignoring edge cases: Always test empty, single element, duplicates
- Memorizing solutions: Focus on understanding the pattern
- Skipping complexity analysis: Always analyze time/space
- Not practicing variations: Each pattern has multiple forms
- Pattern Recognition: 90% accuracy in identifying correct pattern
- Implementation Speed: Solve medium problems in 20-30 minutes
- Edge Case Handling: Cover all cases without hints
- Optimization: Achieve optimal time/space complexity
- Code Quality: Clean, readable, bug-free implementation
Start with the patterns you know (like Two Pointers from your moveZeros work) and gradually expand your toolkit. Consistency beats intensity! 🚀