u/Different-Pie8242

The hard part of LeetCode mediums isn't writing the code. It's figuring out which pattern applies in the first 60 seconds. Once you know the pattern, the implementation is mostly muscle memory.

After ~600 problems and a lot of failed mocks, I built this trigger-word index for myself. Sharing in case it saves anyone the same pain.

For each pattern: when to use it, the trigger words in the problem statement, and 2–3 problems that drill it.

  1. TWO POINTERS

Use when: the array is sorted, OR you're looking for pairs/triplets, OR you're scanning from both ends.

Trigger words: "sorted", "palindrome", "pair sums to", "remove duplicates in place".

Drill: Two Sum II, Valid Palindrome, 3Sum, Container With Most Water.

  1. SLIDING WINDOW

Use when: you need a contiguous subarray or substring matching some constraint.

Trigger words: "longest/shortest substring", "subarray of length k", "at most K distinct".

Drill: Longest Substring Without Repeating Characters, Minimum Window Substring, Longest Repeating Character Replacement.

  1. HASH MAP / SET

Use when: you need to ask "have I seen this before?" in O(1), or count frequencies, or look up complements.

Trigger words: "duplicate", "anagram", "first non-repeating", "two numbers that sum to".

Drill: Two Sum, Group Anagrams, Valid Anagram, Subarray Sum Equals K.

  1. BINARY SEARCH

Use when: input is sorted, OR you can binary-search on the *answer* (the answer space is monotonic).

Trigger words: "sorted", "find the minimum X such that", "log time", "rotated".

Drill: Search in Rotated Sorted Array, Find Minimum in Rotated Sorted Array, Koko Eating Bananas.

Underrated insight: binary-search-on-answer is the highest-value advanced pattern. If a problem says "find the minimum capacity such that..." it's almost always this.

  1. DFS (recursion or stack)

Use when: you need all paths, all combinations, connected components, or tree/graph traversal where order doesn't matter.

Trigger words: "all paths", "permutations", "subsets", "islands", "connected".

Drill: Number of Islands, Word Search, Clone Graph, Path Sum II.

  1. BFS (queue)

Use when: shortest path on an unweighted graph, OR level-by-level traversal.

Trigger words: "shortest path", "level by level", "minimum number of steps".

Drill: Binary Tree Level Order Traversal, Word Ladder, Rotting Oranges.

Common mistake: using DFS for shortest-path problems. DFS will find *a* path, not the shortest.

  1. DYNAMIC PROGRAMMING

Use when: optimization (max/min/count) with overlapping subproblems and a clear recurrence.

Trigger words: "maximum/minimum", "count the number of ways", "longest", with a constraint that depends on prior choices.

Drill: Climbing Stairs, House Robber, Coin Change, Longest Common Subsequence.

Honest take: DP is the hardest pattern to learn fast. The recurrence relation is the bottleneck, not the code. Practice writing the recurrence in plain English before writing any code.

  1. HEAP / PRIORITY QUEUE

Use when: you need the top K, the Kth largest, or a running median.

Trigger words: "top K", "Kth largest/smallest", "median of a stream".

Drill: Kth Largest Element, Top K Frequent Elements, Find Median from Data Stream, Merge K Sorted Lists.

The meta-pattern that actually moves the needle:

When you read a new problem, don't start coding. Spend 60 seconds asking: "What is the input shape, and what's the question shape?"

- Sorted input + pair question → two pointers or binary search

- Contiguous subarray/substring + constraint → sliding window

- "Have I seen X" → hash map

- "All possible Xs" → DFS/backtracking

- "Shortest" on a graph → BFS

- "Top K" or "Kth" → heap

- "Maximum/minimum with overlapping subproblems" → DP

90% of the mediums I've seen fall into one of those buckets. The other 10% combine two patterns (e.g., "Top K Frequent Elements" = hash map + heap).

What's your trigger-word index look like? Curious if anyone has additions for the patterns I left out (monotonic stack, union-find, trie). I left them out because they're high-leverage but lower-frequency in the problem distribution.

reddit.com
u/Different-Pie8242 — 8 days ago