Solve LeetCode by pattern, not by random problem. Learn about twelve patterns, such as hash map, two pointers, sliding window, binary search, tree and graph traversal, backtracking, heap and 1D dynamic programming. For each, study one template, solve three problems, then re-solve them from memory after a few days. No fixed problem count guarantees an offer.
On this page
Why patterns, and how many problems is enoughThe 12 patterns: signal words, template and problemsA 10-week scheduleHow to solve a LeetCode problem, and how to reviewFrequently asked questionsThis roadmap is for students who open LeetCode, solve a few problems, forget them, and feel they are not improving. The fix is to group problems by the idea that solves them, so each new problem looks like an old one.
The 36 problems below are real LeetCode problems. Number, title and difficulty were checked against LeetCode's own site on 1 December 2026. The page does not claim that any number of problems leads to any result, and says why in the section on counts.
- 1FoundationsArrays, hash map, complexity
- 2Pointers and windowsTwo pointers, sliding window
- 3Search and stackBinary search, stack
- 4Trees and graphsDFS, BFS, grids
- 5Recursion familyBacktracking, 1D DP
- 6Heaps and greedyTop k, intervals
- 7Mixed reviewTimed sets, mock rounds
Why patterns, and how many problems is enough
A pattern is a reusable shape of solution: a loop structure and a data structure that fit a family of problems. "Longest substring with a condition" is a sliding window; "fewest moves" is BFS. If you can name the pattern within a minute of reading, you start from a template instead of a blank page.
On how many problems to solve: no verified number exists. Candidates differ in background, target companies and how well they retain what they solved, and LeetCode does not publish a pass mark. This plan uses 36 core problems, three per pattern, and judges progress by something you can test: can you solve a new problem of the same pattern, from a blank file, in 30 to 40 minutes? Twenty problems you can re-solve cold beat a hundred you read the solution for.
If you are earlier than this, begin with the DSA learning path. The time complexity page is the one prerequisite, since every pattern here is justified by complexity.
The 12 patterns: signal words, template and problems
Read the signal words in the problem statement first. They are the cheapest clue. The template column is the shape of the loop, not a full solution. Problem numbers are LeetCode's; difficulties are in brackets (E easy, M medium, H hard).
| Pattern | Signal words | Template | Three problems to practise |
|---|---|---|---|
| 1. Hash map and prefix sum | pair, count, duplicate, subarray sum equals | Store seen values or running totals in a dict, look up the complement | 1 Two Sum (E); 560 Subarray Sum Equals K (M); 238 Product of Array Except Self (M) |
| 2. Two pointers | sorted, pair, triplet, palindrome, in place | Pointers at both ends, move the one that can improve the answer | 125 Valid Palindrome (E); 11 Container With Most Water (M); 15 3Sum (M) |
| 3. Sliding window | longest, shortest, contiguous, at most k | Grow right edge, shrink left while invalid | 3 Longest Substring Without Repeating Characters (M); 209 Minimum Size Subarray Sum (M); 76 Minimum Window Substring (H) |
| 4. Binary search | sorted, rotated, minimum speed or capacity, O(log n) | lo, hi, mid; search an index or the answer itself | 704 Binary Search (E); 33 Search in Rotated Sorted Array (M); 875 Koko Eating Bananas (M) |
| 5. Fast and slow pointers (linked list) | cycle, middle, kth from end | slow moves 1, fast moves 2, or reverse links as you walk | 141 Linked List Cycle (E); 876 Middle of the Linked List (E); 206 Reverse Linked List (E) |
| 6. Stack and monotonic stack | matching, next greater, nested, undo | Push, pop while the top breaks the rule | 20 Valid Parentheses (E); 739 Daily Temperatures (M); 84 Largest Rectangle in Histogram (H) |
| 7. Tree DFS and BFS | binary tree, depth, level, ancestor | Recursion on left and right, or a queue per level | 104 Maximum Depth of Binary Tree (E); 102 Binary Tree Level Order Traversal (M); 236 Lowest Common Ancestor of a Binary Tree (M) |
| 8. Graph and grid BFS/DFS | islands, connected, shortest moves, reachable | Seen set plus queue or stack over neighbours | 200 Number of Islands (M); 133 Clone Graph (M); 994 Rotting Oranges (M) |
| 9. Backtracking | all combinations, permutations, subsets, generate | Choose, recurse, undo the choice | 78 Subsets (M); 46 Permutations (M); 39 Combination Sum (M) |
| 10. Heap and top k | kth largest, top k, median, merge k | Min-heap of size k, or two heaps | 215 Kth Largest Element in an Array (M); 347 Top K Frequent Elements (M); 295 Find Median from Data Stream (H) |
| 11. 1D dynamic programming | ways to, minimum cost, can reach, choose or skip | dp[i] from earlier dp values; base cases first | 70 Climbing Stairs (E); 198 House Robber (M); 322 Coin Change (M) |
| 12. Intervals and greedy | merge, overlap, schedule, jump, best time | Sort by start or end, then one sweep keeping a running best | 56 Merge Intervals (M); 55 Jump Game (M); 121 Best Time to Buy and Sell Stock (E) |
Deep dives on the harder rows: two pointers and sliding window with ten solved problems, BFS vs DFS for rows 7 and 8, backtracking for row 9, heaps for row 10 and dynamic programming for row 11.
One template made concrete: binary search on the answer
Row 4 hides the template people miss. When the question asks for the smallest value that satisfies a condition, and the condition flips from false to true once, you binary search the value, not an array. This is LeetCode 875: find the slowest eating speed that finishes all piles within the hours.
def min_speed(piles, hours):
"""Smallest eating speed k so every pile is finished within `hours`."""
def can_finish(k):
return sum(-(-p // k) for p in piles) <= hours # ceiling division
lo, hi = 1, max(piles)
while lo < hi: # search the ANSWER, not an array index
mid = (lo + hi) // 2
if can_finish(mid):
hi = mid # mid works: try something smaller
else:
lo = mid + 1 # mid is too slow: go bigger
return lo
print(min_speed([3, 6, 7, 11], 8))
print(min_speed([30, 11, 23, 4, 20], 5))
print(min_speed([30, 11, 23, 4, 20], 6))The three lines print 4, 30 and 23. The same lo, hi, mid skeleton reappears in capacity, split array and minimum-days problems. See binary search explained for the array version.
A 10-week schedule
The plan assumes about 6 to 8 hours a week and four to six problems a week. That pace is a suggestion for a student with classes, not a measured requirement. If a week slips, repeat it rather than skipping it.
| Week | Patterns | Work this week | End-of-week check |
|---|---|---|---|
| 1 | 1. Hash map and prefix sum | Read the complexity page. Solve the 3 problems. Write the dict template from memory. | Solve 1 Two Sum cold in 10 minutes |
| 2 | 2. Two pointers, 3. Sliding window | Read the two pointers page. Solve the 6 problems (76 can wait until week 10 if stuck). | Say which pattern applies before coding |
| 3 | 4. Binary search, 5. Linked list pointers | Do the 6 problems. Draw pointer moves on paper for the linked list ones. | Re-solve week 1 problems |
| 4 | 6. Stack | Do the 3 problems and add 1 extra easy stack problem. | Re-solve week 2 problems |
| 5 | 7. Tree DFS and BFS | Do the 3 problems. Write recursion with a stated base case. | Re-solve week 3 problems |
| 6 | 8. Graph and grid | Read BFS vs DFS. Do the 3 problems. | Re-solve week 4 problems |
| 7 | 9. Backtracking | Do the 3 problems. Draw the decision tree for each. | Re-solve week 5 problems |
| 8 | 10. Heap and top k, 11. 1D dynamic programming | Do the 6 problems. For DP, write the recurrence in words first. | Re-solve week 6 problems |
| 9 | 12. Intervals and greedy, plus 743 Network Delay Time | Do the 3 problems, then read the Dijkstra page and try 743 as a stretch. | Re-solve week 7 problems |
| 10 | Mixed review | Two timed sets of 3 unseen medium problems, 40 minutes each, chosen without looking at the topic. | Write the pattern you missed and why |
That is 36 core problems across ten weeks, plus re-solves. For a company-style question list after week 10, use DSA interview questions, and for contest-style practice the competitive programming roadmap.
How to solve a LeetCode problem, and how to review
A routine for each problem
- Read it twice. Write the input size and any sorted or positive hints.
- Name the pattern from the signal words. If nothing fits, write the brute force first and find its repeated work.
- State the complexity of the brute force and the target. The input limits tell you the target.
- Code the template. Run the examples by hand before pressing submit.
- Cap the struggle at 30 to 40 minutes. Then read one hint, not the full solution, and try again.
- After solving, write one line: pattern, the key insight, the mistake you made.
Review schedule that is actually testable
| When | What to do | Pass means |
|---|---|---|
| Same day | Re-type the solution without looking | It runs and matches your notes |
| Day 3 | Solve again from a blank file | No hints, within 20 minutes |
| Day 10 | Solve a different problem of the same pattern | You named the pattern before coding |
| Day 30 | Mixed set of 3 patterns, timed | At least 2 of 3 solved in time |
Keep the log in a plain table with problem, pattern, date, result and the mistake. Patterns you fail twice go to the top of next week's list. Platforms and free sites to practise on are listed in the coding practice websites guide.
Mistakes that waste weeks
- Reading solutions after five minutes. You only learn the pattern if you struggled with the problem first.
- Doing problems in order of the LeetCode list, which mixes patterns at random.
- Solving each problem once. Without repeats, most of the learning fades.
- Skipping the brute force. It is the fallback in an interview and the key to seeing the optimisation.
- Counting problems instead of patterns you can solve cold.
Frequently asked questions
How many LeetCode problems should I solve?
There is no verified number that guarantees anything. A practical target is about three problems per pattern across twelve patterns, so 36 core problems, and being able to re-solve each from a blank file. Quality of review matters more than the count, since two attempts on one problem teach more than two shallow passes.
How do I start LeetCode as a beginner?
Start with easy problems in one pattern at a time: hash map, then two pointers. Learn big-O first so you can judge your solution. Cap each attempt at 30 to 40 minutes, read one hint if stuck, and re-solve after three days. Skip hard problems until you can do mediums in a topic.
What are the most important LeetCode patterns?
Hash map, two pointers, sliding window, binary search, stack, tree and graph traversal with BFS and DFS, backtracking, heaps and 1D dynamic programming appear again and again in interview question lists. This page uses twelve patterns. Which ones a particular company asks most is not published, so cover all twelve.
Is LeetCode enough to crack coding interviews?
It is the most common practice source, but not the only skill. Interviews also test explaining your approach, handling follow-ups and basic design for some roles. Practising aloud and doing timed mocks help. Nothing guarantees an outcome, so treat problem practice as one part of preparation.
How long does it take to learn LeetCode patterns?
The 10-week plan here assumes 6 to 8 hours a week and four to six problems weekly. Some people need longer to retain recursion and dynamic programming. If a pattern fails the day-3 re-solve, repeat the week rather than moving on.
Should I memorise solutions or understand them?
Understand the pattern and re-derive the code. Memorised solutions fail when a problem changes slightly. A good test is to explain why each line exists and to solve a variation, such as the average version of a window sum, without looking.
Which language should I use on LeetCode?
Use the one you know best and can write fast and correctly. Python is compact and common for interviews; Java and C++ are also accepted. Pick one, learn its standard library for heaps, queues and dictionaries, and stay with it through the 10 weeks.
Learn this with mentors
Programmes for builders and engineers with admissions open: live classes, mentors and project work.


