Skip to content
← Back to Blog

Top 10 LeetCode Patterns Every FAANG Candidate Must Know

8 min read

There are hundreds of LeetCode problems, but you do not need to memorize them all. Behind every problem lies a pattern — a reusable technique that solves an entire category of questions. Master these 10 patterns and you will be equipped to handle roughly 80% of the coding interview problems you encounter at FAANG companies.

This guide covers the 10 most frequently tested patterns, ordered by importance. For each pattern, we include when to use it, example problems, time complexity, and a link to our interactive animated walkthrough.

1. Two Pointers

Two Pointers is the workhorse pattern of array problems. Place one pointer at the start and one at the end, then move them inward based on a condition. It turns brute-force O(n²) pair searches into elegant O(n) solutions.

When to use: Use when the input is sorted and you need to find a pair or compare elements from both ends.

Complexity: O(n) time, O(1) space

Example problems: Two Sum II (sorted), 3Sum, Container With Most Water

View interactive walkthrough for Two Pointers

2. Sliding Window

Sliding Window maintains a dynamic range over your array or string. Expand the right boundary to include new elements, shrink the left boundary when a constraint is violated. It handles "longest", "shortest", and "maximum sum" subarray problems.

When to use: Use when looking for a contiguous subarray or substring that meets some condition.

Complexity: O(n) time, O(1) or O(k) space

Example problems: Longest Substring Without Repeating Characters, Minimum Window Substring

View interactive walkthrough for Sliding Window

3. Binary Search

Binary Search goes beyond simple "find the target." The real power is in boundary-finding: binary search on the answer space. If you can frame a problem as "find the smallest X where condition(X) is true" and the condition is monotonic, binary search works.

When to use: Use when searching in sorted data or when you can define a monotonic condition to check.

Complexity: O(log n) time, O(1) space

Example problems: Search in Rotated Sorted Array, Koko Eating Bananas, Capacity To Ship Packages

View interactive walkthrough for Binary Search

4. BFS (Breadth-First Search)

BFS explores layer by layer using a queue. It naturally finds shortest paths in unweighted graphs because it visits closer nodes first. Any problem asking for "minimum moves" or "fewest steps" is almost certainly BFS.

When to use: Use for shortest path in unweighted graphs, level-order tree traversal, or minimum-steps problems.

Complexity: O(V + E) time, O(V) space

Example problems: Binary Tree Level Order Traversal, Rotting Oranges, Word Ladder

View interactive walkthrough for BFS (Breadth-First Search)

5. DFS (Depth-First Search)

DFS dives deep into one path before backtracking. It uses recursion (or an explicit stack) and is the foundation for backtracking, topological sort, and tree traversal. When you need to visit every node or find all connected components, DFS is your tool.

When to use: Use for exploring all paths, connected components, tree depth, or problems requiring exhaustive search.

Complexity: O(V + E) time, O(V) space

Example problems: Number of Islands, Maximum Depth of Binary Tree, Path Sum

View interactive walkthrough for DFS (Depth-First Search)

6. Hash Map / Counting

Hash maps trade space for time. Count frequencies, check membership, or store complements — all in O(1) per operation. The classic Two Sum problem is solved in one pass with a hash map storing complements.

When to use: Use when you need O(1) lookups, frequency counting, or checking for duplicates.

Complexity: O(n) time, O(n) space

Example problems: Two Sum, Group Anagrams, Top K Frequent Elements

View interactive walkthrough for Hash Map / Counting

7. Backtracking

Backtracking systematically builds candidates and abandons them as soon as they cannot lead to a valid solution. It is the go-to pattern for "generate all" problems. The key insight is the choose-explore-unchoose loop.

When to use: Use when you need to generate all combinations, permutations, or solve constraint-satisfaction problems.

Complexity: O(2^n) or O(n!) time

Example problems: Permutations, Subsets, N-Queens, Combination Sum

View interactive walkthrough for Backtracking

8. Dynamic Programming (Fibonacci Pattern)

The Fibonacci DP pattern is the gentlest entry point into dynamic programming. If dp[i] depends only on dp[i-1] and dp[i-2], you can solve it in O(n) time with O(1) space by keeping just two variables. Recognize it by looking for linear sequences of decisions.

When to use: Use when the current state depends on a small number of previous states.

Complexity: O(n) time, O(1) space (optimized)

Example problems: Climbing Stairs, House Robber, Decode Ways

View interactive walkthrough for Dynamic Programming (Fibonacci Pattern)

9. Merge Intervals

Sort intervals by start time, then merge overlapping ones in a single scan. This pattern appears in scheduling problems, calendar conflicts, and any scenario where ranges overlap. Once sorted, the merge logic is straightforward.

When to use: Use when dealing with overlapping intervals, meeting schedules, or range-based problems.

Complexity: O(n log n) time, O(n) space

Example problems: Merge Intervals, Insert Interval, Meeting Rooms

View interactive walkthrough for Merge Intervals

10. Topological Sort

Topological Sort orders vertices of a DAG so that every edge points forward. Use Kahn's algorithm (BFS with in-degree tracking) for iterative solutions. If the sorted order has fewer nodes than the graph, there is a cycle.

When to use: Use for dependency ordering, course prerequisite problems, or cycle detection in directed graphs.

Complexity: O(V + E) time, O(V) space

Example problems: Course Schedule, Course Schedule II, Alien Dictionary

View interactive walkthrough for Topological Sort

How to Study These Patterns

Knowing the patterns is only half the battle. The real skill is recognizing which pattern to apply when you see a new problem. Here is a study approach that works:

  1. Learn one pattern at a time. Read the explanation, understand the pseudocode, then solve 3-5 problems that use that pattern before moving on.
  2. Use the decision tree. Our Pattern Decision Tree asks you 3-5 targeted questions to identify the right pattern for any problem.
  3. Test yourself. Take the Pattern Recognition Quiz to build the intuition of reading a problem description and instantly knowing which pattern to apply.
  4. Review with the cheat sheet. The Cheat Sheet gives you a quick-reference view of all 29 patterns with key indicators and complexities.

Beyond the Top 10

These 10 patterns cover the majority of interview problems, but there are more to explore. Patterns like Monotonic Stack, Trie, Union-Find, and 0/1 Knapsack appear in harder interviews. Browse all 29 patterns to see the complete picture.

You might also be interested in these related guides:

Ready to practice pattern recognition?

Try our interactive tools to build the intuition that separates good engineers from great ones.