A small set of patterns shows up again and again in coding interviews. Start with the essentials, then add the next-level ones. Each guide shows how to spot the pattern and how to code it.
Each step builds on the one before it.
Study in the order of appearance.
Use it when: You need instant lookup, counting or grouping.
Practice: Two Sum, Group Anagrams, Top K Frequent Elements
Read the guide →Use it when: A sorted array, or a pair or triplet that meets a condition.
Practice: Two Sum II, 3Sum, Container With Most Water
Read the guide →Use it when: A contiguous subarray or substring with a max, min or exact condition.
Practice: Longest Substring Without Repeating Characters, Minimum Size Subarray Sum
Read the guide →Use it when: Sorted input, a rotated array, or a yes or no check that flips once (search the answer).
Practice: Search in Rotated Sorted Array, Koko Eating Bananas, Median of Two Sorted Arrays
Read the guide →Use it when: Cycles, the middle node, or reversing and merging lists in place.
Practice: Linked List Cycle, Reverse Linked List, Merge Two Sorted Lists
Read the guide →Use it when: Matching brackets, or the next greater or smaller element.
Practice: Valid Parentheses, Daily Temperatures, Largest Rectangle in Histogram
Read the guide →Use it when: Anything on a tree: depth, paths, ancestors, validity.
Practice: Maximum Depth, Lowest Common Ancestor, Validate Binary Search Tree
Read the guide →Use it when: Connected regions, shortest path with equal steps, reachability.
Practice: Number of Islands, Rotting Oranges, Clone Graph
Read the guide →Use it when: Overlapping ranges and scheduling.
Practice: Merge Intervals, Insert Interval, Meeting Rooms II
Read the guide →Use it when: The kth largest, the most frequent, or merging sorted streams.
Practice: Kth Largest Element, Merge k Sorted Lists, Find Median from Data Stream
Read the guide →Use it when: Generate all combinations, permutations or subsets.
Practice: Subsets, Permutations, N-Queens
Read the guide →Use it when: Overlapping subproblems and an optimal substructure.
Practice: Climbing Stairs, Coin Change, Longest Common Subsequence, Edit Distance
Read the guide →Use it when: Many range-sum queries, or subarrays that add up to k.
Practice: Subarray Sum Equals K, Range Sum Query
Read the guide →Use it when: Order the data first, or find the kth element without a full sort.
Practice: Sort Colors, Kth Largest Element, Merge Intervals
Read the guide →Use it when: A locally best choice at each step leads to the best overall answer.
Practice: Jump Game, Gas Station, Assign Cookies
Read the guide →Use it when: Tasks with dependencies that must run in a valid order.
Practice: Course Schedule, Alien Dictionary
Read the guide →Use it when: Group items into connected sets that merge over time.
Practice: Number of Provinces, Redundant Connection
Read the guide →Use it when: The shortest path in a graph with weighted edges.
Practice: Network Delay Time, Cheapest Flights Within K Stops
Read the guide →Use it when: Many words searched or matched by prefix.
Practice: Implement Trie, Word Search II
Read the guide →Use it when: Build a class with fast operations, such as a cache or an iterator.
Practice: LRU Cache, Min Stack, Time Based Key-Value Store
Read the guide →Each pattern has problems with tested solutions, from Easy to Hard.