The biggest mistake candidates make is grinding 500+ LeetCode problems without a strategy. You do not need to solve every problem on the platform. You need to recognize patterns. When you see a new problem in an interview, your brain should instantly map it to a known pattern and adapt the template. This guide covers the 50 most important patterns grouped into categories, with the exact problems you should solve to internalize each one.
Start with the foundations. Two Pointers is the single most versatile pattern. It applies to sorted arrays, linked lists, and string problems. The classic setup: one pointer at the start, one at the end, moving inward based on a condition. Use it for pair sum problems, removing duplicates, and container with most water. Fast and Slow Pointers (Floyd's cycle detection) solves linked list cycle detection, finding the middle node, and happy number problems. Sliding Window handles substring and subarray problems: longest substring without repeating characters, minimum window substring, maximum sum subarray of size K.
Array and String Patterns (1 through 10). Pattern 1: Two Pointers on sorted arrays. Pattern 2: Fast and slow pointers for cycles. Pattern 3: Sliding window for subarrays and substrings. Pattern 4: Prefix sums for range queries. Pattern 5: Kadane's algorithm for maximum subarray. Pattern 6: Dutch National Flag for three-way partitioning. Pattern 7: Boyer-Moore voting for majority element. Pattern 8: Merge intervals for overlapping ranges. Pattern 9: Cyclic sort for problems involving numbers 1 to N. Pattern 10: In-place reversal for strings and arrays.
Hash Map and Set Patterns (11 through 18). Pattern 11: Frequency counting for anagrams and permutations. Pattern 12: Two sum using hash map lookup. Pattern 13: Group by key (group anagrams). Pattern 14: Sliding window with hash map for character frequency tracking. Pattern 15: Subarray sum equals K using prefix sum plus hash map. Pattern 16: First unique character using ordered hash map. Pattern 17: Longest consecutive sequence using hash set. Pattern 18: Design hash map from scratch (understanding internals).
Binary Search Patterns (19 through 24). Pattern 19: Classic binary search on sorted array. Pattern 20: Binary search on answer (minimize maximum, capacity to ship packages). Pattern 21: Search in rotated sorted array. Pattern 22: Find first and last position of element. Pattern 23: Peak element finding. Pattern 24: Binary search on matrix (search a 2D sorted matrix).
Linked List Patterns (25 through 30). Pattern 25: Reverse a linked list iteratively and recursively. Pattern 26: Merge two sorted lists. Pattern 27: Detect and remove cycle. Pattern 28: Find intersection point of two lists. Pattern 29: Reorder list (interleave front and back). Pattern 30: LRU cache using doubly linked list plus hash map.
Tree and Graph Patterns (31 through 40). Pattern 31: BFS level-order traversal. Pattern 32: DFS preorder, inorder, postorder. Pattern 33: Validate binary search tree. Pattern 34: Lowest common ancestor. Pattern 35: Serialize and deserialize binary tree. Pattern 36: Topological sort for dependency ordering. Pattern 37: Union-Find for connected components. Pattern 38: Dijkstra's shortest path. Pattern 39: BFS for shortest path in unweighted graph. Pattern 40: Clone graph using DFS plus hash map.
Dynamic Programming Patterns (41 through 47). Pattern 41: 0/1 Knapsack and variants. Pattern 42: Longest common subsequence. Pattern 43: Longest increasing subsequence. Pattern 44: Coin change (unbounded knapsack). Pattern 45: Edit distance. Pattern 46: House robber (no two adjacent). Pattern 47: Matrix path problems (unique paths, minimum path sum).
Advanced Patterns (48 through 50). Pattern 48: Monotonic stack for next greater element and largest rectangle in histogram. Pattern 49: Trie for prefix matching and autocomplete. Pattern 50: Backtracking template for permutations, combinations, and subsets.
The study plan: spend two weeks on patterns 1 through 18 (arrays, strings, hash maps). Then one week on binary search (19 through 24). One week on linked lists (25 through 30). Two weeks on trees and graphs (31 through 40). Two weeks on dynamic programming (41 through 47). One week on advanced patterns (48 through 50). Solve three problems per pattern: one easy, one medium, one hard. That is 150 problems total, and you will be better prepared than someone who solved 500 randomly. Recognition beats repetition every time.
Continue Reading
This content is available with BliniBot Pro or as an individual purchase.