Skip to content

Automedon/ultimate-leetcode-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

The Ultimate High-ROI LeetCode Patterns Guide

41 patterns, 20 problems each, all free — no Premium garbage. Sorted top to bottom by how often each pattern actually shows up in interviews. Hash Map and Sliding Window first because they're everywhere. Segment Tree and Fenwick Tree last because almost nobody asks them. Inside each pattern: Easy to Hard, so you're not getting wrecked by a Hard problem before you've even nailed the basic version of the trick.

How to actually use this:

Don't grind all 820. That's a waste of your time and most of this list won't come up. Drill the first 10-15 patterns until you don't have to think — you see the problem, your hands already know the code. Everything below that is bonus coverage for if your interviewer likes to go off-script. Speed matters more than breadth here: 45 minutes isn't a lot of time, and if you're still figuring out syntax halfway through, you're not getting to the part where you actually look good.

Hard truths about the process:

Most loops are decided on the first problem.

Speed and clean code beat a late correct answer.

Follow-ups exist to catch memorized solutions.

You're graded against other candidates that week, not a fixed bar.

Patterns

1. Hash Map / Hash Set
2. Sliding Window
3. Two Pointers
4. Binary Search
5. Prefix Sum
6. String Manipulation / Parsing
7. String Matching / Pattern Search
8. Stack
9. Monotonic Stack / Queue (Specific Variants)
10. Queue / Deque
11. Tree DFS (Preorder / Inorder / Postorder)
12. Tree BFS (Level Order)
13. Dynamic Programming - 1D
14. Recursion / Divide and Conquer
15. Backtracking / Subsets / Combinations / Permutations
16. Graph DFS
17. Graph BFS
18. Matrix / Grid Traversal
19. Heap / Priority Queue
20. Intervals (Merge / Insert / Overlap)
21. Greedy
22. Dynamic Programming - 2D / Grid
23. Sorting
24. Fast & Slow Pointers (Linked List)
25. Linked List Reversal / Manipulation
26. Binary Search Tree (BST)
27. Bit Manipulation
28. Dynamic Programming - Knapsack Style
29. Design Problems
30. Topological Sort
31. Union-Find (Disjoint Set)
32. Trie (Prefix Tree)
33. Cyclic Sort
34. Math / Number Theory
35. Sliding Window Maximum / Minimum (Specific Variants)
36. Simulation / Array Rearrangement
37. Two Heaps
38. K-way Merge
39. Game Theory / Minimax
40. Segment Tree
41. Binary Indexed Tree (Fenwick Tree)


1. Hash Map / Hash Set

  1. Two Sum (Easy)
  2. Contains Duplicate (Easy)
  3. Valid Anagram (Easy)
  4. Isomorphic Strings (Easy)
  5. Word Pattern (Easy)
  6. Ransom Note (Easy)
  7. Longest Palindrome (Easy)
  8. Number of Equivalent Domino Pairs (Easy)
  9. Group Anagrams (Medium)
  10. Top K Frequent Elements (Medium)
  11. Longest Consecutive Sequence (Medium)
  12. Subarray Sum Equals K (Medium)
  13. Find the Duplicate Number (Medium)
  14. Four Sum II (Medium)
  15. Brick Wall (Medium)
  16. Check If a String Contains All Binary Codes of Size K (Medium)
  17. Continuous Subarray Sum (Medium)
  18. Insert Delete GetRandom O(1) (Medium)
  19. Subarrays with K Different Integers (Hard)
  20. First Missing Positive (Hard)

Back to top

2. Sliding Window

  1. Best Time to Buy and Sell Stock (Easy)
  2. Longest Substring Without Repeating Characters (Medium)
  3. Minimum Size Subarray Sum (Medium)
  4. Longest Repeating Character Replacement (Medium)
  5. Permutation in String (Medium)
  6. Find All Anagrams in a String (Medium)
  7. Fruit Into Baskets (Medium)
  8. Max Consecutive Ones III (Medium)
  9. Subarray Product Less Than K (Medium)
  10. Longest Subarray of 1's After Deleting One Element (Medium)
  11. Maximum Number of Vowels in a Substring of Given Length (Medium)
  12. Count Number of Nice Subarrays (Medium)
  13. Binary Subarrays With Sum (Medium)
  14. Maximum Erasure Value (Medium)
  15. Grumpy Bookstore Owner (Medium)
  16. Frequency of the Most Frequent Element (Medium)
  17. Minimum Number of Flips to Make the Binary String Alternating (Medium)
  18. Minimum Window Substring (Hard)
  19. Sliding Window Maximum (Hard)
  20. Subarrays with K Different Integers (Hard)

Back to top

3. Two Pointers

  1. Valid Palindrome (Easy)
  2. Reverse String (Easy)
  3. Move Zeroes (Easy)
  4. Remove Element (Easy)
  5. Squares of a Sorted Array (Easy)
  6. Remove Duplicates from Sorted Array (Easy)
  7. Valid Palindrome II (Easy)
  8. Backspace String Compare (Easy)
  9. Two Sum II - Input Array Is Sorted (Medium)
  10. Remove Duplicates from Sorted Array II (Medium)
  11. Sort Colors (Medium)
  12. Rotate Array (Medium)
  13. 4Sum (Medium)
  14. Sort Array By Parity II (Easy)
  15. Container With Most Water (Medium)
  16. Partition Labels (Medium)
  17. Boats to Save People (Medium)
  18. Number of Subsequences That Satisfy the Given Sum Condition (Medium)
  19. Trapping Rain Water (Hard)
  20. Minimum Window Subsequence (Hard)

Back to top

4. Binary Search

  1. Binary Search (Easy)
  2. Search Insert Position (Easy)
  3. Sqrt(x) (Easy)
  4. Find First and Last Position of Element in Sorted Array (Medium)
  5. Search in Rotated Sorted Array (Medium)
  6. Search in Rotated Sorted Array II (Medium)
  7. Find Minimum in Rotated Sorted Array (Medium)
  8. Search a 2D Matrix (Medium)
  9. Koko Eating Bananas (Medium)
  10. Capacity To Ship Packages Within D Days (Medium)
  11. Find Peak Element (Medium)
  12. Find the Smallest Divisor Given a Threshold (Medium)
  13. Kth Smallest Element in a Sorted Matrix (Medium)
  14. Single Element in a Sorted Array (Medium)
  15. Time Based Key-Value Store (Medium)
  16. Minimum Number of Days to Make m Bouquets (Medium)
  17. Find K Closest Elements (Medium)
  18. Peak Index in a Mountain Array (Medium)
  19. Median of Two Sorted Arrays (Hard)
  20. Split Array Largest Sum (Hard)

Back to top

5. Prefix Sum

  1. Range Sum Query - Immutable (Easy)
  2. Find Pivot Index (Easy)
  3. Find the Highest Altitude (Easy)
  4. Range Sum Query 2D - Immutable (Medium)
  5. Subarray Sum Equals K (Medium)
  6. Maximum Size Subarray Sum Equals k — substitute: Contiguous Array (Medium)
  7. Product of Array Except Self (Medium)
  8. Continuous Subarray Sum (Medium)
  9. Maximum Subarray (Medium)
  10. Path Sum III (Medium)
  11. Count Number of Nice Subarrays (Medium)
  12. Binary Subarrays With Sum (Medium)
  13. Number of Sub-arrays With Odd Sum (Medium)
  14. Minimum Value to Get Positive Step by Step Sum (Medium)
  15. Maximum Sum of Two Non-Overlapping Subarrays (Medium)
  16. Range Sum Query - Mutable (Medium)
  17. Make Sum Divisible by P (Medium)
  18. Matrix Block Sum (Medium)
  19. Count Square Submatrices with All Ones (Medium)
  20. Number of Ways to Split Array (Medium)

Back to top

6. String Manipulation / Parsing

  1. Valid Parentheses (Easy)
  2. Longest Common Prefix (Easy)
  3. Repeated Substring Pattern (Easy)
  4. Implement strStr() — substitute: Find the Index of the First Occurrence in a String (Easy)
  5. String to Integer (atoi) (Medium)
  6. Zigzag Conversion (Medium)
  7. Group Anagrams (Medium)
  8. Multiply Strings (Medium)
  9. Compare Version Numbers (Medium)
  10. Decode Ways (Medium)
  11. Simplify Path (Medium)
  12. Word Break (Medium)
  13. Longest Palindromic Substring (Medium)
  14. Count and Say (Medium)
  15. Group Shifted Strings (Medium)
  16. Reorganize String (Medium)
  17. Decode String (Medium)
  18. Text Justification (Hard)
  19. Basic Calculator (Hard)
  20. Minimum Window Substring (Hard)

Back to top

7. String Matching / Pattern Search

  1. Implement strStr() — substitute: Find the Index of the First Occurrence in a String (Easy)
  2. Repeated Substring Pattern (Easy)
  3. Valid Anagram (Easy)
  4. Shortest Distance to a Character (Easy)
  5. Index Pairs of a String (Easy)
  6. Find All Anagrams in a String (Medium)
  7. Permutation in String (Medium)
  8. Longest Palindromic Substring (Medium)
  9. Group Shifted Strings (Medium)
  10. Camelcase Matching (Medium)
  11. Number of Matching Subsequences (Medium)
  12. Shortest Palindrome (Hard)
  13. Wildcard Matching (Hard)
  14. Regular Expression Matching (Hard)
  15. Longest Happy Prefix (Hard)
  16. Find All Good Strings — substitute: Distinct Echo Substrings (Hard)
  17. Minimum Window Substring (Hard)
  18. Stream of Characters (Hard)
  19. Palindrome Pairs (Hard)
  20. Concatenated Words (Hard)

Back to top

8. Stack

  1. Valid Parentheses (Easy)
  2. Remove All Adjacent Duplicates in String (Easy)
  3. Make The String Great (Easy)
  4. Next Greater Element I (Easy)
  5. Backspace String Compare (Easy)
  6. Build a String From Another String — substitute: Baseball Game (Easy)
  7. Min Stack (Medium)
  8. Evaluate Reverse Polish Notation (Medium)
  9. Generate Parentheses (Medium)
  10. Daily Temperatures (Medium)
  11. Decode String (Medium)
  12. Asteroid Collision (Medium)
  13. Simplify Path (Medium)
  14. Basic Calculator II (Medium)
  15. Remove All Adjacent Duplicates in String II (Medium)
  16. Score of Parentheses (Medium)
  17. Exclusive Time of Functions (Medium)
  18. Minimum Add to Make Parentheses Valid (Medium)
  19. Validate Stack Sequences (Medium)
  20. Basic Calculator (Hard)

Back to top

9. Monotonic Stack / Queue (Specific Variants)

  1. Next Greater Element I (Easy)
  2. Daily Temperatures (Medium)
  3. Next Greater Element II (Medium)
  4. Remove K Digits (Medium)
  5. Remove Duplicate Letters (Medium)
  6. Sum of Subarray Minimums (Medium)
  7. Online Stock Span (Medium)
  8. 132 Pattern (Medium)
  9. Car Fleet (Medium)
  10. Next Greater Node In Linked List (Medium)
  11. Find the Most Competitive Subsequence (Medium)
  12. Maximum Width Ramp (Medium)
  13. Sum of Subarray Ranges (Medium)
  14. Steps to Make Array Non-decreasing (Medium)
  15. Largest Rectangle in Histogram (Hard)
  16. Trapping Rain Water (Hard)
  17. Maximal Rectangle (Hard)
  18. Sliding Window Maximum (Hard)
  19. Shortest Subarray with Sum at Least K (Hard)
  20. Constrained Subsequence Sum (Hard)

Back to top

10. Queue / Deque

  1. Implement Queue using Stacks (Easy)
  2. Implement Stack using Queues (Easy)
  3. Moving Average from Data Stream — substitute: Number of Recent Calls (Easy)
  4. Time Needed to Buy Tickets (Easy)
  5. Design Circular Queue (Medium)
  6. Design Circular Deque (Medium)
  7. Dota2 Senate (Medium)
  8. Reveal Cards In Increasing Order (Medium)
  9. Design Front Middle Back Queue (Medium)
  10. Maximum Number of Robots Within Budget (Medium)
  11. First Unique Number (Medium)
  12. Design Snake Game (Medium)
  13. Sum of Subarray Minimums (Medium)
  14. Jump Game VI (Medium)
  15. Find the Winner of the Circular Game (Medium)
  16. Maximum Sum of Two Non-Overlapping Subarrays (Medium)
  17. Sliding Window Maximum (Hard)
  18. Shortest Subarray with Sum at Least K (Hard)
  19. Constrained Subsequence Sum (Hard)
  20. Stamping The Sequence (Hard)

Back to top

11. Tree DFS (Preorder / Inorder / Postorder)

  1. Binary Tree Inorder Traversal (Easy)
  2. Binary Tree Preorder Traversal (Easy)
  3. Binary Tree Postorder Traversal (Easy)
  4. Maximum Depth of Binary Tree (Easy)
  5. Path Sum (Easy)
  6. Diameter of Binary Tree (Easy)
  7. Balanced Binary Tree (Easy)
  8. Same Tree (Easy)
  9. Symmetric Tree (Easy)
  10. Invert Binary Tree (Easy)
  11. Path Sum II (Medium)
  12. Lowest Common Ancestor of a Binary Tree (Medium)
  13. Construct Binary Tree from Preorder and Inorder Traversal (Medium)
  14. Flatten Binary Tree to Linked List (Medium)
  15. Sum Root to Leaf Numbers (Medium)
  16. Path Sum III (Medium)
  17. Count Good Nodes in Binary Tree (Medium)
  18. Binary Tree Pruning (Medium)
  19. All Nodes Distance K in Binary Tree (Medium)
  20. Binary Tree Maximum Path Sum (Hard)

Back to top

12. Tree BFS (Level Order)

  1. Average of Levels in Binary Tree (Easy)
  2. Minimum Depth of Binary Tree (Easy)
  3. Cousins in Binary Tree (Easy)
  4. N-ary Tree Level Order Traversal (Easy)
  5. Binary Tree Level Order Traversal (Medium)
  6. Binary Tree Level Order Traversal II (Medium)
  7. Binary Tree Zigzag Level Order Traversal (Medium)
  8. Binary Tree Right Side View (Medium)
  9. Populating Next Right Pointers in Each Node (Medium)
  10. Populating Next Right Pointers in Each Node II (Medium)
  11. Maximum Width of Binary Tree (Medium)
  12. Find Largest Value in Each Tree Row (Medium)
  13. Binary Tree Vertical Order Traversal — substitute: Find Bottom Left Tree Value (Medium)
  14. Add One Row to Tree (Medium)
  15. Level Order Traversal Distinct Values — substitute: Deepest Leaves Sum (Medium)
  16. Smallest String Starting From Leaf (Medium)
  17. Binary Tree Coloring Game (Medium)
  18. Step-By-Step Directions From a Binary Tree Node to Another (Medium)
  19. Check Completeness of a Binary Tree (Medium)
  20. Cousins in Binary Tree II (Medium)

Back to top

13. Dynamic Programming - 1D

  1. Climbing Stairs (Easy)
  2. House Robber (Medium)
  3. House Robber II (Medium)
  4. Maximum Subarray (Medium)
  5. Coin Change (Medium)
  6. Longest Increasing Subsequence (Medium)
  7. Word Break (Medium)
  8. Decode Ways (Medium)
  9. Jump Game (Medium)
  10. Maximum Product Subarray (Medium)
  11. Best Time to Buy and Sell Stock with Cooldown (Medium)
  12. Partition Equal Subset Sum (Medium)
  13. Coin Change II (Medium)
  14. Combination Sum IV (Medium)
  15. Perfect Squares (Medium)
  16. Wiggle Subsequence (Medium)
  17. Number of Longest Increasing Subsequence (Medium)
  18. Minimum Cost For Tickets (Medium)
  19. Delete and Earn (Medium)
  20. Maximum Length of Repeated Subarray (Medium)

Back to top

14. Recursion / Divide and Conquer

  1. Convert Sorted Array to Binary Search Tree (Easy)
  2. Merge Sort — substitute: Sort an Array (Medium)
  3. Pow(x, n) (Medium)
  4. Maximum Subarray (Medium)
  5. Different Ways to Add Parentheses (Medium)
  6. Kth Largest Element in an Array (Medium)
  7. Construct Binary Tree from Preorder and Inorder Traversal (Medium)
  8. Beautiful Array (Medium)
  9. Unique Binary Search Trees II (Medium)
  10. Maximum Score Words Formed by Letters (Medium)
  11. Super Pow (Medium)
  12. The Skyline Problem (Hard)
  13. Count of Smaller Numbers After Self (Hard)
  14. Median of Two Sorted Arrays (Hard)
  15. Reverse Pairs (Hard)
  16. Expression Add Operators (Hard)
  17. Strange Printer (Hard)
  18. Minimum Cost to Merge Stones (Hard)
  19. Burst Balloons (Hard)
  20. Count of Range Sum (Hard)

Back to top

15. Backtracking / Subsets / Combinations / Permutations

  1. Subsets (Medium)
  2. Letter Case Permutation (Medium)
  3. Generate Parentheses (Medium)
  4. Combinations (Medium)
  5. Combination Sum (Medium)
  6. Subsets II (Medium)
  7. Permutations (Medium)
  8. Permutations II (Medium)
  9. Combination Sum II (Medium)
  10. Combination Sum III (Medium)
  11. Letter Combinations of a Phone Number (Medium)
  12. Beautiful Arrangement (Medium)
  13. Word Search (Medium)
  14. Palindrome Partitioning (Medium)
  15. Restore IP Addresses (Medium)
  16. Gray Code (Medium)
  17. Factor Combinations (Medium)
  18. Partition to K Equal Sum Subsets (Medium)
  19. N-Queens (Hard)
  20. Sudoku Solver (Hard)

Back to top

16. Graph DFS

  1. Flood Fill (Easy)
  2. Number of Islands (Medium)
  3. Max Area of Island (Medium)
  4. Clone Graph (Medium)
  5. Pacific Atlantic Water Flow (Medium)
  6. Surrounded Regions (Medium)
  7. Course Schedule (Medium)
  8. Number of Provinces (Medium)
  9. Number of Enclaves (Medium)
  10. Keys and Rooms (Medium)
  11. Reorder Routes to Make All Paths Lead to the City Zero (Medium)
  12. All Paths From Source to Target (Medium)
  13. Find Eventual Safe States (Medium)
  14. Number of Closed Islands (Medium)
  15. Time Needed to Inform All Employees (Medium)
  16. Most Stones Removed with Same Row or Column (Medium)
  17. Detonate the Maximum Bombs (Medium)
  18. Count Sub Islands (Medium)
  19. Path with Maximum Probability (Medium)
  20. Making A Large Island (Hard)

Back to top

17. Graph BFS

  1. Rotting Oranges (Medium)
  2. 01 Matrix (Medium)
  3. Shortest Path in Binary Matrix (Medium)
  4. Open the Lock (Medium)
  5. Snakes and Ladders (Medium)
  6. Nearest Exit from Entrance in Maze (Medium)
  7. As Far from Land as Possible (Medium)
  8. Shortest Path with Alternating Colors (Medium)
  9. Jump Game III (Medium)
  10. Minimum Genetic Mutation (Medium)
  11. Cheapest Flights Within K Stops (Medium)
  12. Shortest Bridge (Medium)
  13. Get Watched Videos by Your Friends (Medium)
  14. Walls and Gates — substitute: Map of Highest Peak (Medium)
  15. Word Ladder (Hard)
  16. Bus Routes (Hard)
  17. Shortest Path to Get All Keys (Hard)
  18. Minimum Number of Days to Disconnect Island (Hard)
  19. Shortest Path in a Grid with Obstacles Elimination (Hard)
  20. Word Ladder II (Hard)

Back to top

18. Matrix / Grid Traversal

  1. Island Perimeter (Easy)
  2. Flood Fill (Easy)
  3. Toeplitz Matrix (Easy)
  4. Transpose Matrix (Easy)
  5. Number of Islands (Medium)
  6. Rotting Oranges (Medium)
  7. Spiral Matrix (Medium)
  8. Spiral Matrix II (Medium)
  9. Rotate Image (Medium)
  10. Set Matrix Zeroes (Medium)
  11. Word Search (Medium)
  12. Pacific Atlantic Water Flow (Medium)
  13. Surrounded Regions (Medium)
  14. 01 Matrix (Medium)
  15. Diagonal Traverse (Medium)
  16. Game of Life (Medium)
  17. Shortest Path in Binary Matrix (Medium)
  18. Number of Distinct Islands (Medium)
  19. Where Will the Ball Fall (Medium)
  20. Unique Paths III (Hard)

Back to top

19. Heap / Priority Queue

  1. Last Stone Weight (Easy)
  2. Kth Largest Element in a Stream (Easy)
  3. The K Weakest Rows in a Matrix (Easy)
  4. Take Gifts From the Richest Pile (Easy)
  5. Kth Largest Element in an Array (Medium)
  6. Top K Frequent Elements (Medium)
  7. K Closest Points to Origin (Medium)
  8. Task Scheduler (Medium)
  9. Reorganize String (Medium)
  10. Sort Characters By Frequency (Medium)
  11. Minimum Cost to Connect Sticks (Medium)
  12. Furthest Building You Can Reach (Medium)
  13. Single-Threaded CPU (Medium)
  14. Maximum Subsequence Score (Medium)
  15. Find the Kth Largest Integer in the Array (Medium)
  16. Top K Frequent Words (Medium)
  17. Seat Reservation Manager (Medium)
  18. Total Cost to Hire K Workers (Medium)
  19. Maximum Performance of a Team (Hard)
  20. Process Tasks Using Servers (Hard)

Back to top

20. Intervals (Merge / Insert / Overlap)

  1. Merge Intervals (Medium)
  2. Insert Interval (Medium)
  3. Non-overlapping Intervals (Medium)
  4. Minimum Number of Arrows to Burst Balloons (Medium)
  5. Interval List Intersections (Medium)
  6. My Calendar I (Medium)
  7. My Calendar II (Medium)
  8. Car Pooling (Medium)
  9. Maximum Number of Events That Can Be Attended (Medium)
  10. Video Stitching (Medium)
  11. Remove Covered Intervals (Medium)
  12. Partition Labels (Medium)
  13. Teemo Attacking — substitute: Meeting Scheduler — substitute: Find Right Interval (Medium)
  14. Employee Free Time (Hard)
  15. My Calendar III (Hard)
  16. Minimum Interval to Include Each Query (Hard)
  17. Range Module (Hard)
  18. Minimum Number of Taps to Open to Water a Garden (Hard)
  19. Data Stream as Disjoint Intervals (Hard)
  20. Falling Squares (Hard)

Back to top

21. Greedy

  1. Lemonade Change (Easy)
  2. Maximum Units on a Truck (Easy)
  3. Jump Game (Medium)
  4. Jump Game II (Medium)
  5. Gas Station (Medium)
  6. Partition Labels (Medium)
  7. Task Scheduler (Medium)
  8. Non-overlapping Intervals (Medium)
  9. Minimum Number of Arrows to Burst Balloons (Medium)
  10. Best Time to Buy and Sell Stock II (Medium)
  11. Two City Scheduling (Medium)
  12. Boats to Save People (Medium)
  13. Greedy Florist — substitute: Maximum Number of Events That Can Be Attended (Medium)
  14. Minimum Add to Make Parentheses Valid (Medium)
  15. Remove K Digits (Medium)
  16. Queue Reconstruction by Height (Medium)
  17. Wiggle Subsequence (Medium)
  18. Candy (Hard)
  19. Minimum Number of Taps to Open to Water a Garden (Hard)
  20. Course Schedule III (Hard)

Back to top

22. Dynamic Programming - 2D / Grid

  1. Unique Paths (Medium)
  2. Unique Paths II (Medium)
  3. Minimum Path Sum (Medium)
  4. Longest Common Subsequence (Medium)
  5. Maximal Square (Medium)
  6. Triangle (Medium)
  7. Interleaving String (Medium)
  8. Minimum Falling Path Sum (Medium)
  9. Count Square Submatrices with All Ones (Medium)
  10. Maximum Points You Can Obtain from Cards (Medium)
  11. Out of Boundary Paths (Medium)
  12. Where Will the Ball Fall (Medium)
  13. Edit Distance (Hard)
  14. Distinct Subsequences (Hard)
  15. Dungeon Game (Hard)
  16. Maximal Rectangle (Hard)
  17. Cherry Pickup (Hard)
  18. Cherry Pickup II (Hard)
  19. Minimum Falling Path Sum II (Hard)
  20. Longest Increasing Path in a Matrix (Hard)

Back to top

23. Sorting

  1. Merge Sorted Array (Easy)
  2. Sort Array By Parity (Easy)
  3. Relative Sort Array (Easy)
  4. Sort the People (Easy)
  5. Sort Array by Increasing Frequency (Easy)
  6. Sort Integers by The Number of 1 Bits (Easy)
  7. Sort Colors (Medium)
  8. Largest Number (Medium)
  9. Merge Intervals (Medium)
  10. Kth Largest Element in an Array (Medium)
  11. Sort an Array (Medium)
  12. Wiggle Sort II (Medium)
  13. Queue Reconstruction by Height (Medium)
  14. Maximum Gap (Medium)
  15. Custom Sort String (Medium)
  16. H-Index (Medium)
  17. Minimum Increment to Make Array Unique (Medium)
  18. Pancake Sorting (Medium)
  19. Sort the Matrix Diagonally (Medium)
  20. Boats to Save People (Medium)

Back to top

24. Fast & Slow Pointers (Linked List)

  1. Linked List Cycle (Easy)
  2. Middle of the Linked List (Easy)
  3. Happy Number (Easy)
  4. Palindrome Linked List (Easy)
  5. Intersection of Two Linked Lists (Easy)
  6. Remove Duplicates from Sorted List (Easy)
  7. Linked List Cycle II (Medium)
  8. Remove Nth Node From End of List (Medium)
  9. Find the Duplicate Number (Medium)
  10. Reorder List (Medium)
  11. Maximum Twin Sum of a Linked List (Medium)
  12. Split Linked List in Parts (Medium)
  13. Delete the Middle Node of a Linked List (Medium)
  14. Rotate List (Medium)
  15. Convert Sorted List to Binary Search Tree (Medium)
  16. Linked List Components (Medium)
  17. Next Greater Node In Linked List (Medium)
  18. Odd Even Linked List (Medium)
  19. Partition List (Medium)
  20. Sort List (Medium)

Back to top

25. Linked List Reversal / Manipulation

  1. Reverse Linked List (Easy)
  2. Merge Two Sorted Lists (Easy)
  3. Remove Linked List Elements (Easy)
  4. Convert Binary Number in a Linked List to Integer (Easy)
  5. Reverse Linked List II (Medium)
  6. Swap Nodes in Pairs (Medium)
  7. Add Two Numbers (Medium)
  8. Add Two Numbers II (Medium)
  9. Copy List with Random Pointer (Medium)
  10. Flatten a Multilevel Doubly Linked List (Medium)
  11. Design Linked List (Medium)
  12. Swapping Nodes in a Linked List (Medium)
  13. Insertion Sort List (Medium)
  14. Plus One Linked List (Medium)
  15. Design a Stack With Increment Operation (Medium)
  16. Odd Even Linked List (Medium)
  17. Merge In Between Linked Lists (Medium)
  18. LRU Cache (Medium)
  19. Reverse Nodes in k-Group (Hard)
  20. Merge k Sorted Lists (Hard)

Back to top

26. Binary Search Tree (BST)

  1. Search in a Binary Search Tree (Easy)
  2. Lowest Common Ancestor of a Binary Search Tree (Easy)
  3. Convert Sorted Array to Binary Search Tree (Easy)
  4. Minimum Absolute Difference in BST (Easy)
  5. Range Sum of BST (Easy)
  6. Two Sum IV - Input is a BST (Easy)
  7. Find Mode in Binary Search Tree (Easy)
  8. Closest Binary Search Tree Value (Easy)
  9. Validate Binary Search Tree (Medium)
  10. Insert into a Binary Search Tree (Medium)
  11. Delete Node in a BST (Medium)
  12. Kth Smallest Element in a BST (Medium)
  13. Convert BST to Greater Tree (Medium)
  14. Balance a Binary Search Tree (Medium)
  15. Trim a Binary Search Tree (Medium)
  16. Recover Binary Search Tree (Medium)
  17. Unique Binary Search Trees (Medium)
  18. Unique Binary Search Trees II (Medium)
  19. Binary Search Tree Iterator (Medium)
  20. Construct Binary Search Tree from Preorder Traversal (Medium)

Back to top

27. Bit Manipulation

  1. Single Number (Easy)
  2. Number of 1 Bits (Easy)
  3. Counting Bits (Easy)
  4. Missing Number (Easy)
  5. Reverse Bits (Easy)
  6. Find the Difference (Easy)
  7. Binary Number with Alternating Bits (Easy)
  8. XOR Operation in an Array (Easy)
  9. Single Number II (Medium)
  10. Single Number III (Medium)
  11. Sum of Two Integers (Medium)
  12. Bitwise AND of Numbers Range (Medium)
  13. Maximum XOR of Two Numbers in an Array (Medium)
  14. Total Hamming Distance (Medium)
  15. UTF-8 Validation (Medium)
  16. Gray Code (Medium)
  17. Subsets (Medium)
  18. Divide Two Integers (Medium)
  19. Maximum Product of Word Lengths (Medium)
  20. Minimum Flips to Make a OR b Equal to c (Medium)

Back to top

28. Dynamic Programming - Knapsack Style

  1. Partition Equal Subset Sum (Medium)
  2. Target Sum (Medium)
  3. Coin Change (Medium)
  4. Coin Change II (Medium)
  5. Last Stone Weight II (Medium)
  6. Ones and Zeroes (Medium)
  7. Combination Sum IV (Medium)
  8. Perfect Squares (Medium)
  9. Partition to K Equal Sum Subsets (Medium)
  10. Minimum Cost to Reach Destination in Time — substitute: Number of Dice Rolls With Target Sum (Medium)
  11. Filling Bookcase Shelves (Medium)
  12. Maximum Students Taking Exam — substitute: Shopping Offers (Medium)
  13. Form Largest Integer With Digit Costs (Medium)
  14. Maximum Number of Points with Cost — substitute: Count Square Submatrices with All Ones (Medium)
  15. Tallest Billboard (Hard)
  16. Profitable Schemes (Hard)
  17. Matrix Block Sum — substitute: Minimum Number of Refueling Stops (Hard)
  18. Maximum Value of K Coins From Piles (Hard)
  19. Closest Subsequence Sum (Hard)
  20. Number of Ways to Stay in the Same Place After Some Steps (Hard)

Back to top

29. Design Problems

  1. Design HashMap (Easy)
  2. LRU Cache (Medium)
  3. Min Stack (Medium)
  4. Implement Trie (Prefix Tree) (Medium)
  5. Design Twitter (Medium)
  6. Insert Delete GetRandom O(1) (Medium)
  7. Design Underground System (Medium)
  8. Design Browser History (Medium)
  9. Time Based Key-Value Store (Medium)
  10. Design Circular Deque (Medium)
  11. Snapshot Array (Medium)
  12. Design a Stack With Increment Operation (Medium)
  13. Online Stock Span (Medium)
  14. Design Add and Search Words Data Structure (Medium)
  15. Stock Price Fluctuation (Medium)
  16. Design a Food Rating System (Medium)
  17. Design Authentication Manager (Medium)
  18. LFU Cache (Hard)
  19. Find Median from Data Stream (Hard)
  20. Serialize and Deserialize Binary Tree (Hard)

Back to top

30. Topological Sort

  1. Course Schedule (Medium)
  2. Course Schedule II (Medium)
  3. Find Eventual Safe States (Medium)
  4. Course Schedule IV (Medium)
  5. Minimum Height Trees (Medium)
  6. All Ancestors of a Node in a Directed Acyclic Graph (Medium)
  7. Parallel Courses (Medium)
  8. Find All Possible Recipes from Given Supplies (Medium)
  9. Loud and Rich (Medium)
  10. Minimum Number of Vertices to Reach All Nodes (Medium)
  11. Sequence Reconstruction (Medium)
  12. Number of Ways to Arrive at Destination (Medium)
  13. Detect Cycles in 2D Grid (Medium)
  14. Parallel Courses III (Hard)
  15. Sort Items by Groups Respecting Dependencies (Hard)
  16. Build a Matrix With Conditions (Hard)
  17. Largest Color Value in a Directed Graph (Hard)
  18. Maximum Employees to Be Invited to a Meeting (Hard)
  19. Strange Printer II (Hard)
  20. Sum of Scores of Built Strings — substitute: Eventual Safe States variant: Longest Cycle in a Graph (Hard)

Back to top

31. Union-Find (Disjoint Set)

  1. Find if Path Exists in Graph (Easy)
  2. Number of Provinces (Medium)
  3. Redundant Connection (Medium)
  4. Accounts Merge (Medium)
  5. Most Stones Removed with Same Row or Column (Medium)
  6. Number of Operations to Make Network Connected (Medium)
  7. Satisfiability of Equality Equations (Medium)
  8. Smallest String With Swaps (Medium)
  9. Lexicographically Smallest Equivalent String (Medium)
  10. Count Unreachable Pairs of Nodes in an Undirected Graph (Medium)
  11. Minimize Malware Spread (Medium)
  12. Regions Cut By Slashes (Medium)
  13. Longest Consecutive Sequence (Medium)
  14. Minimize the Maximum of Two Arrays — substitute: The Earliest Moment When Everyone Become Friends (Medium)
  15. Redundant Connection II (Hard)
  16. Graph Connectivity With Threshold (Hard)
  17. Making A Large Island (Hard)
  18. Checking Existence of Edge Length Limited Paths (Hard)
  19. Largest Component Size by Common Factor (Hard)
  20. Remove Max Number of Edges to Keep Graph Fully Traversable (Hard)

Back to top

32. Trie (Prefix Tree)

  1. Longest Word in Dictionary (Easy)
  2. Count Pairs of Similar Strings — substitute: Index Pairs of a String (Easy)
  3. Implement Trie (Prefix Tree) (Medium)
  4. Design Add and Search Words Data Structure (Medium)
  5. Implement Trie II (Prefix Tree) (Medium)
  6. Replace Words (Medium)
  7. Map Sum Pairs (Medium)
  8. Maximum XOR of Two Numbers in an Array (Medium)
  9. Search Suggestions System (Medium)
  10. Word Break (Medium)
  11. Camelcase Matching (Medium)
  12. Number of Matching Subsequences (Medium)
  13. Short Encoding of Words (Medium)
  14. Word Search II (Hard)
  15. Concatenated Words (Hard)
  16. Stream of Characters (Hard)
  17. Prefix and Suffix Search (Hard)
  18. Maximum XOR With an Element From Array (Hard)
  19. Sum of Prefix Scores of Strings (Hard)
  20. Palindrome Pairs (Hard)

Back to top

33. Cyclic Sort

  1. Missing Number (Easy)
  2. Find All Numbers Disappeared in an Array (Easy)
  3. Set Mismatch (Easy)
  4. Move Zeroes (Easy)
  5. Degree of an Array (Easy)
  6. Number of Good Pairs (Easy)
  7. Replace Elements with Greatest Element on Right Side (Easy)
  8. Find the Difference (Easy)
  9. Single Number (Easy)
  10. Find All Duplicates in an Array (Medium)
  11. Find the Duplicate Number (Medium)
  12. Sort Colors (Medium)
  13. Minimum Number of Swaps to Make the String Balanced (Medium)
  14. Array Nesting (Medium)
  15. Maximum Swap (Medium)
  16. Smallest Range II (Medium)
  17. Wiggle Sort II (Medium)
  18. Maximum Number of Integers to Choose From a Range I (Medium)
  19. First Missing Positive (Hard)
  20. Couples Holding Hands (Hard)

Back to top

34. Math / Number Theory

  1. Palindrome Number (Easy)
  2. Sqrt(x) (Easy)
  3. Roman to Integer (Easy)
  4. Excel Sheet Column Number (Easy)
  5. Excel Sheet Column Title (Easy)
  6. Greatest Common Divisor of Strings (Easy)
  7. Happy Number (Easy)
  8. Add Digits (Easy)
  9. Ugly Number (Easy)
  10. Self Dividing Numbers (Easy)
  11. Reverse Integer (Medium)
  12. Pow(x, n) (Medium)
  13. Integer to Roman (Medium)
  14. Count Primes (Medium)
  15. Factorial Trailing Zeroes (Medium)
  16. Fraction to Recurring Decimal (Medium)
  17. Ugly Number II (Medium)
  18. Super Pow (Medium)
  19. Water and Jug Problem (Medium)
  20. Nth Digit (Medium)

Back to top

35. Sliding Window Maximum / Minimum (Specific Variants)

  1. Maximum Average Subarray I (Easy)
  2. Maximum Sum of Almost Unique Subarray — substitute: Minimum Recolors to Get K Consecutive Black Blocks (Easy)
  3. Jump Game VI (Medium)
  4. Maximum Number of Robots Within Budget (Medium)
  5. Sum of Subarray Minimums (Medium)
  6. Sum of Subarray Ranges (Medium)
  7. Continuous Subarrays — substitute: Maximum Side Length of a Square with Sum Less than or Equal to Threshold (Medium)
  8. Subarray Product Less Than K (Medium)
  9. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit (Medium)
  10. Frequency of the Most Frequent Element (Medium)
  11. Grumpy Bookstore Owner (Medium)
  12. Maximum Points You Can Obtain from Cards (Medium)
  13. Minimum Number of Flips to Make the Binary String Alternating (Medium)
  14. Maximum Erasure Value (Medium)
  15. Find the Longest Equal Subarray (Medium)
  16. Sliding Window Maximum (Hard)
  17. Shortest Subarray with Sum at Least K (Hard)
  18. Constrained Subsequence Sum (Hard)
  19. Minimum Window Substring (Hard)
  20. Count Subarrays With Fixed Bounds (Hard)

Back to top

36. Simulation / Array Rearrangement

  1. Pascal's Triangle (Easy)
  2. Reshape the Matrix (Easy)
  3. Image Smoother (Easy)
  4. Plus One (Easy)
  5. Rotate Array (Medium)
  6. Spiral Matrix II (Medium)
  7. Game of Life (Medium)
  8. Candy Crush (Medium)
  9. Robot Bounded In Circle (Medium)
  10. Spiral Matrix III (Medium)
  11. Design a Number Container System (Medium)
  12. Snakes and Ladders (Medium)
  13. Minesweeper (Medium)
  14. Out of Boundary Paths (Medium)
  15. Diagonal Traverse II (Medium)
  16. Cyclically Rotating a Grid (Medium)
  17. Maximum Matrix Sum (Medium)
  18. Magic Squares In Grid (Medium)
  19. Rotating the Box (Medium)
  20. Stamping the Grid (Hard)

Back to top

37. Two Heaps

  1. Take Gifts From the Richest Pile (Easy)
  2. Kth Largest Element in a Stream (Easy)
  3. Last Stone Weight (Easy)
  4. Minimum Cost to Hire K Workers — substitute: Total Cost to Hire K Workers (Medium)
  5. Furthest Building You Can Reach (Medium)
  6. Single-Threaded CPU (Medium)
  7. Seat Reservation Manager (Medium)
  8. Maximum Subsequence Score (Medium)
  9. The Number of the Smallest Unoccupied Chair (Medium)
  10. Maximum Average Pass Ratio (Medium)
  11. Find Right Interval (Medium)
  12. Reorganize String (Medium)
  13. Task Scheduler (Medium)
  14. Find Median from Data Stream (Hard)
  15. Sliding Window Median (Hard)
  16. IPO (Hard)
  17. Constrained Subsequence Sum (Hard)
  18. Maximum Performance of a Team (Hard)
  19. Process Tasks Using Servers (Hard)
  20. Minimize Deviation in Array (Hard)

Back to top

38. K-way Merge

  1. Merge Two Sorted Lists (Easy)
  2. Merge Sorted Array (Easy)
  3. The K Weakest Rows in a Matrix (Easy)
  4. Kth Smallest Element in a Sorted Matrix (Medium)
  5. Find K Pairs with Smallest Sums (Medium)
  6. Ugly Number II (Medium)
  7. Super Ugly Number (Medium)
  8. Sort the Matrix Diagonally (Medium)
  9. Find K Closest Elements (Medium)
  10. K Closest Points to Origin (Medium)
  11. Minimum Cost to Connect Sticks (Medium)
  12. Maximum Number of Eaten Apples (Medium)
  13. Top K Frequent Elements (Medium)
  14. Kth Largest Element in an Array (Medium)
  15. Merge k Sorted Lists (Hard)
  16. Smallest Range Covering Elements from K Lists (Hard)
  17. Kth Smallest Number in Multiplication Table (Hard)
  18. Find K-th Smallest Pair Distance (Hard)
  19. K-th Smallest Prime Fraction (Hard)
  20. Find the Kth Smallest Sum of a Matrix With Sorted Rows (Hard)

Back to top

39. Game Theory / Minimax

  1. Nim Game (Easy)
  2. Divisor Game (Easy)
  3. Optimal Strategy — substitute: Flip Game (Easy)
  4. Stone Game (Medium)
  5. Stone Game II (Medium)
  6. Stone Game VI (Medium)
  7. Stone Game VII (Medium)
  8. Predict the Winner (Medium)
  9. Can I Win (Medium)
  10. Guess Number Higher or Lower II (Medium)
  11. Minimax Game — substitute: Min and Max (Medium)
  12. Find the Winner of the Circular Game (Medium)
  13. Maximum Number of Coins You Can Get (Medium)
  14. Stone Game IX (Medium)
  15. Maximum Score from Performing Multiplication Operations (Medium)
  16. Stone Game III (Hard)
  17. Stone Game IV (Hard)
  18. Cat and Mouse (Hard)
  19. Minimum Number of Moves to Make Palindrome (Hard)
  20. Stone Game VIII (Hard)

Back to top

40. Segment Tree

  1. Range Sum Query - Mutable (Medium)
  2. My Calendar I (Medium)
  3. My Calendar II (Medium)
  4. Create Sorted Array through Instructions (Medium)
  5. Number of Longest Increasing Subsequence (Medium)
  6. Range Frequency Queries (Medium)
  7. Longest Uploaded Prefix (Medium)
  8. Count of Smaller Numbers After Self (Hard)
  9. Count of Range Sum (Hard)
  10. Reverse Pairs (Hard)
  11. The Skyline Problem (Hard)
  12. Falling Squares (Hard)
  13. Range Module (Hard)
  14. My Calendar III (Hard)
  15. Rectangle Area II (Hard)
  16. Longest Increasing Subsequence II (Hard)
  17. Handling Sum Queries After Update (Hard)
  18. Booking Concert Tickets in Groups (Hard)
  19. Find Building Where Alice and Bob Can Meet (Hard)
  20. Number of Pairs Satisfying Inequality (Hard)

Back to top

41. Binary Indexed Tree (Fenwick Tree)

  1. Range Sum Query - Mutable (Medium)
  2. Range Sum Query 2D - Mutable — substitute: Range Sum Query 2D - Immutable (Medium)
  3. Create Sorted Array through Instructions (Medium)
  4. Queue Reconstruction by Height (Medium)
  5. Count Number of Teams (Medium)
  6. Longest Increasing Subsequence (Medium)
  7. Number of Longest Increasing Subsequence (Medium)
  8. The Number of Weak Characters in the Game (Medium)
  9. Best Team With No Conflicts (Medium)
  10. Range Frequency Queries (Medium)
  11. Count of Smaller Numbers After Self (Hard)
  12. Count of Range Sum (Hard)
  13. Reverse Pairs (Hard)
  14. Russian Doll Envelopes (Hard)
  15. Number of Pairs Satisfying Inequality (Hard)
  16. Make Array Empty (Hard)
  17. Count Good Triplets in an Array (Hard)
  18. Maximum Balanced Subsequence Sum (Hard)
  19. Sum of Floored Pairs (Hard)
  20. Peaks in Array (Hard)

Back to top

About

LeetCode patterns guide for coding interviews — 41 patterns, 820 free problems (no Premium), sorted by real interview frequency and difficulty. Two Pointers, Sliding Window, DP, Graphs, Backtracking, and more.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors