LeetCode Problems by Pattern: A Pattern-Wise List
All 310 LeetCode problems FaangPrep teaches, grouped by the pattern that solves them. Search for a problem to see which pattern it belongs to, then open its lesson to watch the solution run step by step.
To learn the patterns themselves first, each heading links to its pattern page, and the patterns cheat sheet has a code template and the signals for each. Problems on the Blind 75 and the NeetCode 150 are marked B75 and NC150.
310 problems
Two Pointers (35)
- Reverse StringEasyLeetCode
- Reverse Vowels of a StringEasyLeetCode
- Reverse Words in a StringMediumLeetCode
- Two Sum II - Input Array Is Sorted
- Max Number of K-Sum PairsMediumLeetCode
- Valid Palindrome
- Merge Strings AlternatelyEasyLeetCode
- Merge Sorted ArrayEasyLeetCode
- Remove Duplicates from Sorted ArrayEasyLeetCode
- String CompressionMediumLeetCode
- Remove ElementEasyLeetCode
- Rotate ArrayMediumLeetCode
- Next PermutationMediumLeetCode
- Repeated String MatchMediumLeetCode
- Find the Index of the First Occurrence in a StringEasyLeetCode
- Shortest PalindromeHardLeetCode
- Squares of a Sorted ArrayEasyLeetCode
- Is SubsequenceEasyLeetCode
- Valid Palindrome IIEasyLeetCode
- Longest Palindromic Substring
- Palindromic Substrings
- Encode and Decode Strings
- Container With Most Water
- 3-Sum
- 3Sum ClosestMediumLeetCode
- 4SumMediumLeetCode
- Valid Triangle NumberMediumLeetCode
- Move ZeroesEasyLeetCode
- Sort ColorsMediumLeetCode
- Trapping Rain Water
- Multiply Strings
- String to Integer (atoi)MediumLeetCode
- Add BinaryEasyLeetCode
- Add StringsEasyLeetCode
- Plus One
Hash Map (20)
- Two Sum
- Contains Duplicate
- Find the Difference of Two ArraysEasyLeetCode
- Unique Number of OccurrencesEasyLeetCode
- Valid Anagram
- Longest PalindromeEasyLeetCode
- Determine if Two Strings Are CloseMediumLeetCode
- Equal Row and Column PairsMediumLeetCode
- Group Anagrams
- Top K Frequent Elements
- Longest Consecutive Sequence
- Valid Sudoku
- Detect Squares
- Majority ElementEasyLeetCode
- Majority Element IIMediumLeetCode
- Isomorphic StringsEasyLeetCode
- Word PatternEasyLeetCode
- Ransom NoteEasyLeetCode
- First Unique Character in a StringEasyLeetCode
- Roman to IntegerEasyLeetCode
Sliding Window (20)
- Maximum Number of Vowels in a Substring of Given LengthMediumLeetCode
- Longest Subarray of 1's After Deleting One ElementMediumLeetCode
- Longest Substring Without Repeating Characters
- Longest Repeating Character Replacement
- Minimum Window Substring
- Minimum Size Subarray SumMediumLeetCode
- Max Consecutive Ones IIIMediumLeetCode
- Binary Subarrays With SumMediumLeetCode
- Count Number of Nice SubarraysMediumLeetCode
- Number of Substrings Containing All Three CharactersMediumLeetCode
- Fruit Into BasketsMediumLeetCode
- Longest Substring with At Most K Distinct CharactersMediumLeetCode
- Number of Recent CallsEasyLeetCode
- Contains Duplicate IIEasyLeetCode
- Overview (Fixed Length)MediumLeetCode
- Maximum Points You Can Obtain from CardsMediumLeetCode
- Maximum Sum of Distinct Subarrays With Length KMediumLeetCode
- Permutation in String
- Find All Anagrams in a StringMediumLeetCode
- Sliding Window Maximum
Intervals (8)
Linked List (22)
- Reverse Linked List
- Middle of the Linked ListEasyLeetCode
- Delete the Middle Node of a Linked ListMediumLeetCode
- Odd Even Linked ListMediumLeetCode
- Maximum Twin Sum of a Linked ListMediumLeetCode
- Intersection of Two Linked ListsEasyLeetCode
- Merge Two Sorted Lists
- Add Two Numbers
- Linked List Cycle
- Linked List Cycle IIMediumLeetCode
- Sort ListMediumLeetCode
- Rotate ListMediumLeetCode
- Palindrome Linked ListEasyLeetCode
- Remove Nth Node From End of List
- Reorder List
- Swap Nodes in PairsMediumLeetCode
- LRU Cache
- LFU CacheHardLeetCode
- Find the Duplicate Number
- Copy List with Random Pointer
- Reverse Nodes in k-Group
- Happy Number
Stack (22)
- Valid Parentheses
- Decode StringMediumLeetCode
- Longest Valid ParenthesesHardLeetCode
- Daily Temperatures
- Largest Rectangle in Histogram
- Maximal RectangleHardLeetCode
- Evaluate Reverse Polish Notation
- Min Stack
- Implement Queue using StacksEasyLeetCode
- Car Fleet
- Next Greater Element IEasyLeetCode
- Next Greater Element IIMediumLeetCode
- Asteroid CollisionMediumLeetCode
- Online Stock SpanMediumLeetCode
- Sum of Subarray MinimumsMediumLeetCode
- Sum of Subarray RangesMediumLeetCode
- Remove K DigitsMediumLeetCode
- Simplify PathMediumLeetCode
- Basic Calculator IIMediumLeetCode
- Basic CalculatorHardLeetCode
- Removing Stars From a StringMediumLeetCode
- Remove All Adjacent Duplicates in StringEasyLeetCode
Binary Search (18)
- Binary Search
- Search Insert PositionEasyLeetCode
- First Bad VersionEasyLeetCode
- Guess Number Higher or LowerEasyLeetCode
- Single Element in a Sorted ArrayMediumLeetCode
- Sqrt(x)EasyLeetCode
- Valid Perfect SquareEasyLeetCode
- Find Peak ElementMediumLeetCode
- Find a Peak Element IIMediumLeetCode
- Apple Harvest (Koko Variant)
- Split Array Largest SumHardLeetCode
- Search in Rotated Sorted Array
- Search in Rotated Sorted Array IIMediumLeetCode
- Find Minimum in Rotated Sorted Array
- Search a 2D Matrix
- Search a 2D Matrix IIMediumLeetCode
- Time Based Key-Value Store
- Median of Two Sorted Arrays
Heap / Priority Queue (12)
- Kth Largest Element in an Array
- Kth Largest Element in a Stream
- K Closest Points to Origin
- Find K Closest ElementsMediumLeetCode
- Merge K Sorted Lists
- Design Twitter
- Kth Smallest Element in a Sorted MatrixMediumLeetCode
- Find Median from Data Stream
- Last Stone Weight
- Network Delay Time
- Min Cost to Connect All Points
- Swim in Rising Water
Depth-First Search (37)
- Invert Binary Tree
- Maximum Depth of Binary Tree
- Same Tree
- Balanced Binary Tree
- Subtree of Another Tree
- Path SumEasyLeetCode
- Validate Binary Search Tree
- Kth Smallest Element in a BST
- Delete Node in a BSTMediumLeetCode
- Search in a Binary Search TreeEasyLeetCode
- Insert into a Binary Search TreeMediumLeetCode
- Inorder Successor in BSTMediumLeetCode
- Largest BST SubtreeMediumLeetCode
- Vertical Order Traversal of a Binary TreeHardLeetCode
- Recover Binary Search TreeMediumLeetCode
- Construct Binary Search Tree from Preorder TraversalMediumLeetCode
- Construct Binary Tree from Preorder and Inorder Traversal
- Serialize and Deserialize Binary Tree
- Binary Tree TiltEasyLeetCode
- Diameter of Binary Tree
- Lowest Common Ancestor of a Binary TreeMediumLeetCode
- Path Sum IIMediumLeetCode
- Count Good Nodes in Binary Tree
- Longest Univalue PathMediumLeetCode
- Graphs Overview
- Graph Representation: Adjacency ListMediumLeetCode
- Clone Graph
- Graph Valid Tree
- Flood FillEasyLeetCode
- Binary Tree Inorder TraversalEasyLeetCode
- Two Sum IV - Input is a BSTEasyLeetCode
- Number of Islands
- Making A Large IslandHardLeetCode
- Number of Distinct IslandsMediumLeetCode
- Surrounded Regions
- Pacific Atlantic Water Flow
- Longest Increasing Path in a Matrix
Breadth-First Search (15)
- BFS Fundamentals & PatternsEasyLeetCode
- Level Order Sum / AveragesMediumLeetCode
- Binary Tree Level Order Traversal
- Symmetric TreeEasyLeetCode
- Binary Tree Rightmost Node (Right Side View)
- Zigzag Level Order TraversalMediumLeetCode
- Maximum Width of Binary TreeMediumLeetCode
- All Nodes Distance K in Binary TreeMediumLeetCode
- Minimum Knight MovesMediumLeetCode
- Rotting Oranges
- Walls and Gates
- 01 MatrixMediumLeetCode
- Bus RoutesHardLeetCode
- Word Ladder
- Cheapest Flights Within K Stops
Backtracking (14)
Graphs (Topological Sort) (12)
- Course Schedule
- Course Schedule II
- Minimum Height TreesMediumLeetCode
- Alien Dictionary
- Redundant Connection
- Accounts MergeMediumLeetCode
- Critical Connections in a NetworkHardLeetCode
- Number of ProvincesMediumLeetCode
- Is Graph Bipartite?MediumLeetCode
- Number of Operations to Make Network ConnectedMediumLeetCode
- Path With Minimum EffortMediumLeetCode
- Reconstruct Itinerary
Dynamic Programming (38)
- Fibonacci NumberEasyLeetCode
- N-th Tribonacci NumberEasyLeetCode
- Counting Bits
- Pascal's TriangleEasyLeetCode
- Min Cost Climbing Stairs
- House Robber
- House Robber II
- House Robber IIIMediumLeetCode
- Coin Change
- Coin Change II
- Maximum Product Subarray
- Combination Sum IV
- Partition Equal Subset Sum
- Last Stone Weight IIMediumLeetCode
- Target Sum
- Decode Ways
- Maximal SquareMediumLeetCode
- Unique Paths
- Unique Paths IIMediumLeetCode
- Minimum Path SumMediumLeetCode
- TriangleMediumLeetCode
- Longest Common Subsequence
- Longest Palindromic SubsequenceMediumLeetCode
- Palindrome Partitioning IIHardLeetCode
- Edit Distance
- Interleaving String
- Distinct Subsequences
- Regular Expression Matching
- Wildcard MatchingHardLeetCode
- Burst Balloons
- Best Time to Buy and Sell Stock with Cooldown
- Best Time to Buy and Sell Stock with Transaction FeeMediumLeetCode
- Best Time to Buy and Sell Stock IIIHardLeetCode
- Best Time to Buy and Sell Stock IVHardLeetCode
- Longest Increasing Subsequence
- Number of Longest Increasing SubsequenceMediumLeetCode
- Word Break
- Maximum Profit in Job SchedulingHardLeetCode
Greedy Algorithms (16)
- Kids With the Greatest Number of CandiesEasyLeetCode
- Can Place FlowersEasyLeetCode
- Dota2 SenateMediumLeetCode
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock IIMediumLeetCode
- Increasing Triplet SubsequenceMediumLeetCode
- Gas Station
- Jump Game
- Jump Game II
- Task Scheduler
- Partition Labels
- Valid Parenthesis String
- Hand of Straights
- Merge Triplets to Form Target Triplet
- Integer to RomanMediumLeetCode
- CandyHardLeetCode
Trie (4)
Prefix Sum (5)
Matrices (3)
Bit Manipulation (9)
Finding the pattern
How do I identify the pattern in a LeetCode problem?
Read the input and what is asked before thinking about code. A sorted array or "pair with sum" points to two pointers; "longest or shortest contiguous subarray" to a sliding window; "k-th largest" or "top k" to a heap; "all combinations or permutations" to backtracking; "minimum steps" on a grid or graph to BFS; "number of ways" or "best value" built from smaller answers to dynamic programming. These are starting points, not rules: check that the pattern actually handles the constraints.
Can one problem use more than one pattern?
Yes. Many problems combine two, for example binary search on the answer with a greedy check, or a hash map inside a sliding window. This list puts each problem under the pattern its main idea uses; the lesson explains the rest.
Should I solve problems by pattern or at random?
Learning by pattern is faster at first, because each problem reuses the idea from the one before it. Once the patterns are familiar, mix them up, since an interview will not tell you which pattern to use.
How is this different from the Blind 75 or the NeetCode 150?
Those are fixed lists chosen by their authors. This page is every problem FaangPrep teaches, grouped by pattern, and it grows as lessons are added. Problems on those lists are marked so you can follow either one here.
