Why Patterns Beat Memorization

Trying to memorize every LeetCode problem is a losing strategy — there are thousands of them. The better approach is to internalize patterns: recurring structures that appear across many problems. Once you recognize a pattern, solving new problems becomes dramatically faster.

Here are the 7 most impactful patterns to master before your next technical interview.

1. Sliding Window

Used for problems involving contiguous subarrays or substrings. Instead of re-computing from scratch for every window position, you slide a boundary and update incrementally.

Applies to: Maximum sum subarray of size K, Longest substring without repeating characters, Minimum window substring.

2. Two Pointers

Place one pointer at each end (or both at the start) and move them toward each other based on conditions. Ideal for sorted arrays and linked list problems.

Applies to: Two Sum (sorted), Container With Most Water, Remove Duplicates, Palindrome check.

3. Fast & Slow Pointers (Floyd's Cycle Detection)

Two pointers move at different speeds through a sequence. The fast pointer moves twice as fast. If there's a cycle, the two pointers will eventually meet.

Applies to: Linked List Cycle, Find the Duplicate Number, Middle of Linked List.

4. Merge Intervals

Sort intervals by start time, then merge overlapping ones. Any time a problem asks you to combine, overlap, or deduplicate ranges — this pattern applies.

Applies to: Merge Intervals, Insert Interval, Meeting Rooms.

5. BFS / Level-Order Traversal

Use a queue to traverse a graph or tree level by level. BFS naturally finds shortest paths in unweighted graphs and is perfect for "minimum steps" problems.

Applies to: Binary Tree Level Order Traversal, Word Ladder, Rotting Oranges, Shortest Path in Grid.

6. Backtracking

Build a solution incrementally and abandon a branch ("backtrack") as soon as you know it can't lead to a valid solution. Used for problems asking for all combinations, permutations, or valid configurations.

Applies to: Subsets, Permutations, N-Queens, Sudoku Solver, Word Search.

7. Binary Search on Answer

Don't just apply binary search on sorted arrays — apply it on the answer space. If you can define a monotonic condition (e.g., "is X feasible?"), you can binary search for the optimal X.

Applies to: Koko Eating Bananas, Minimum Capacity to Ship, Find the Smallest Divisor.

How to Practice Patterns Effectively

  1. Pick one pattern per week and solve 8–10 problems exclusively using that pattern.
  2. After solving, write a one-sentence summary of why that pattern applied.
  3. Revisit problems from earlier weeks without looking at your notes — can you still identify the pattern?
  4. Mix patterns: many hard problems require combining two (e.g., sliding window + hash map).

Pattern Recognition at a Glance

Signal in the ProblemTry This Pattern
"Contiguous subarray/substring"Sliding Window
"Sorted array, find pair/triplet"Two Pointers
"Cycle in linked list"Fast & Slow Pointers
"Overlapping intervals"Merge Intervals
"Shortest path / minimum steps"BFS
"All valid combinations"Backtracking
"Minimize/maximize some value"Binary Search on Answer

Final Advice

During an interview, spend the first 2–3 minutes categorizing the problem before writing code. Saying "this looks like a sliding window problem because we're dealing with a contiguous substring" signals strong problem-solving instincts — which interviewers notice and reward.