Ecommet

Free DSA sheet

Crack coding interviews, one pattern at a time

151 problems that come up again and again in interviews, in 18 topics from arrays and hashing to graphs and dynamic programming. Every one has a plain-English explanation, a naive and an optimal approach, and tested code in Java and Python.

  • 151 problems
  • 18 topics
  • Java + Python
  • Free, no sign-up
Progress options

01 Arrays & Hashing Where every interview starts: scanning arrays, counting with hash maps and sets, and prefix sums. 0 / 15
  1. 1 Two Sum Easy Practice Two Sum on LeetCode (opens in a new tab)
  2. 2 Contains Duplicate Easy Practice Contains Duplicate on LeetCode (opens in a new tab)
  3. 3 Valid Anagram Easy Practice Valid Anagram on LeetCode (opens in a new tab)
  4. 4 Best Time to Buy and Sell Stock Easy Practice Best Time to Buy and Sell Stock on LeetCode (opens in a new tab)
  5. 5 Majority Element Easy Practice Majority Element on LeetCode (opens in a new tab)
  6. 6 Move Zeroes Easy Practice Move Zeroes on LeetCode (opens in a new tab)
  7. 7 Merge Sorted Array Easy Practice Merge Sorted Array on LeetCode (opens in a new tab)
  8. 8 Group Anagrams Medium Practice Group Anagrams on LeetCode (opens in a new tab)
  9. 9 Top K Frequent Elements Medium Practice Top K Frequent Elements on LeetCode (opens in a new tab)
  10. 10 Product of Array Except Self Medium Practice Product of Array Except Self on LeetCode (opens in a new tab)
  11. 11 Longest Consecutive Sequence Medium Practice Longest Consecutive Sequence on LeetCode (opens in a new tab)
  12. 12 Maximum Subarray Medium Practice Maximum Subarray on LeetCode (opens in a new tab)
  13. 13 Subarray Sum Equals K Medium Practice Subarray Sum Equals K on LeetCode (opens in a new tab)
  14. 14 Sort Colors Medium Practice Sort Colors on LeetCode (opens in a new tab)
  15. 15 Next Permutation Medium Practice Next Permutation on LeetCode (opens in a new tab)

About the Arrays & Hashing problems

02 Two Pointers Two indexes moving through an array or string, usually from both ends, to replace a nested loop with a single pass. 0 / 6
  1. 16 Valid Palindrome Easy Practice Valid Palindrome on LeetCode (opens in a new tab)
  2. 17 Remove Duplicates from Sorted Array Easy Practice Remove Duplicates from Sorted Array on LeetCode (opens in a new tab)
  3. 18 Two Sum II – Input Array Is Sorted Medium Practice Two Sum II – Input Array Is Sorted on LeetCode (opens in a new tab)
  4. 19 3Sum Medium Practice 3Sum on LeetCode (opens in a new tab)
  5. 20 Container With Most Water Medium Practice Container With Most Water on LeetCode (opens in a new tab)
  6. 21 Trapping Rain Water Hard Practice Trapping Rain Water on LeetCode (opens in a new tab)

About the Two Pointers problems

03 Sliding Window A range over an array or string that grows on the right and shrinks on the left, for "longest" or "shortest" substring and subarray questions. 0 / 6
  1. 22 Longest Substring Without Repeating Characters Medium Practice Longest Substring Without Repeating Characters on LeetCode (opens in a new tab)
  2. 23 Longest Repeating Character Replacement Medium Practice Longest Repeating Character Replacement on LeetCode (opens in a new tab)
  3. 24 Permutation in String Medium Practice Permutation in String on LeetCode (opens in a new tab)
  4. 25 Max Consecutive Ones III Medium Practice Max Consecutive Ones III on LeetCode (opens in a new tab)
  5. 26 Minimum Window Substring Hard Practice Minimum Window Substring on LeetCode (opens in a new tab)
  6. 27 Sliding Window Maximum Hard Practice Sliding Window Maximum on LeetCode (opens in a new tab)

About the Sliding Window problems

04 Matrix 2D arrays: walking rows and columns, rotating and transforming in place, and using the grid itself as storage. 0 / 5
  1. 28 Pascal’s Triangle Easy Practice Pascal’s Triangle on LeetCode (opens in a new tab)
  2. 29 Set Matrix Zeroes Medium Practice Set Matrix Zeroes on LeetCode (opens in a new tab)
  3. 30 Rotate Image Medium Practice Rotate Image on LeetCode (opens in a new tab)
  4. 31 Spiral Matrix Medium Practice Spiral Matrix on LeetCode (opens in a new tab)
  5. 32 Valid Sudoku Medium Practice Valid Sudoku on LeetCode (opens in a new tab)

About the Matrix problems

05 Stack Last in, first out: matching brackets, evaluating expressions, and monotonic stacks for "next greater" questions. 0 / 7
  1. 33 Valid Parentheses Easy Practice Valid Parentheses on LeetCode (opens in a new tab)
  2. 34 Next Greater Element I Easy Practice Next Greater Element I on LeetCode (opens in a new tab)
  3. 35 Min Stack Medium Practice Min Stack on LeetCode (opens in a new tab)
  4. 36 Evaluate Reverse Polish Notation Medium Practice Evaluate Reverse Polish Notation on LeetCode (opens in a new tab)
  5. 37 Daily Temperatures Medium Practice Daily Temperatures on LeetCode (opens in a new tab)
  6. 38 Asteroid Collision Medium Practice Asteroid Collision on LeetCode (opens in a new tab)
  7. 39 Largest Rectangle in Histogram Hard Practice Largest Rectangle in Histogram on LeetCode (opens in a new tab)

About the Stack problems

06 Binary Search Halving the search space each step: sorted arrays, rotated arrays, and searching over the answer itself. 0 / 8
  1. 40 Binary Search Easy Practice Binary Search on LeetCode (opens in a new tab)
  2. 41 Search a 2D Matrix Medium Practice Search a 2D Matrix on LeetCode (opens in a new tab)
  3. 42 Find First and Last Position of Element in Sorted Array Medium Practice Find First and Last Position of Element in Sorted Array on LeetCode (opens in a new tab)
  4. 43 Find Peak Element Medium Practice Find Peak Element on LeetCode (opens in a new tab)
  5. 44 Koko Eating Bananas Medium Practice Koko Eating Bananas on LeetCode (opens in a new tab)
  6. 45 Find Minimum in Rotated Sorted Array Medium Practice Find Minimum in Rotated Sorted Array on LeetCode (opens in a new tab)
  7. 46 Search in Rotated Sorted Array Medium Practice Search in Rotated Sorted Array on LeetCode (opens in a new tab)
  8. 47 Median of Two Sorted Arrays Hard Practice Median of Two Sorted Arrays on LeetCode (opens in a new tab)

About the Binary Search problems

07 Linked List Pointer surgery: reversing, merging, fast and slow pointers, and dummy heads that remove edge cases. 0 / 14
  1. 48 Reverse Linked List Easy Practice Reverse Linked List on LeetCode (opens in a new tab)
  2. 49 Merge Two Sorted Lists Easy Practice Merge Two Sorted Lists on LeetCode (opens in a new tab)
  3. 50 Linked List Cycle Easy Practice Linked List Cycle on LeetCode (opens in a new tab)
  4. 51 Middle of the Linked List Easy Practice Middle of the Linked List on LeetCode (opens in a new tab)
  5. 52 Palindrome Linked List Easy Practice Palindrome Linked List on LeetCode (opens in a new tab)
  6. 53 Intersection of Two Linked Lists Easy Practice Intersection of Two Linked Lists on LeetCode (opens in a new tab)
  7. 54 Remove Nth Node From End of List Medium Practice Remove Nth Node From End of List on LeetCode (opens in a new tab)
  8. 55 Linked List Cycle II Medium Practice Linked List Cycle II on LeetCode (opens in a new tab)
  9. 56 Reorder List Medium Practice Reorder List on LeetCode (opens in a new tab)
  10. 57 Add Two Numbers Medium Practice Add Two Numbers on LeetCode (opens in a new tab)
  11. 58 Copy List with Random Pointer Medium Practice Copy List with Random Pointer on LeetCode (opens in a new tab)
  12. 59 LRU Cache Medium Practice LRU Cache on LeetCode (opens in a new tab)
  13. 60 Merge k Sorted Lists Hard Practice Merge k Sorted Lists on LeetCode (opens in a new tab)
  14. 61 Reverse Nodes in k-Group Hard Practice Reverse Nodes in k-Group on LeetCode (opens in a new tab)

About the Linked List problems

08 Trees Binary trees and binary search trees: recursion, depth-first and breadth-first traversal, and passing information up and down. 0 / 18
  1. 62 Binary Tree Inorder Traversal Easy Practice Binary Tree Inorder Traversal on LeetCode (opens in a new tab)
  2. 63 Maximum Depth of Binary Tree Easy Practice Maximum Depth of Binary Tree on LeetCode (opens in a new tab)
  3. 64 Invert Binary Tree Easy Practice Invert Binary Tree on LeetCode (opens in a new tab)
  4. 65 Same Tree Easy Practice Same Tree on LeetCode (opens in a new tab)
  5. 66 Symmetric Tree Easy Practice Symmetric Tree on LeetCode (opens in a new tab)
  6. 67 Diameter of Binary Tree Easy Practice Diameter of Binary Tree on LeetCode (opens in a new tab)
  7. 68 Balanced Binary Tree Easy Practice Balanced Binary Tree on LeetCode (opens in a new tab)
  8. 69 Subtree of Another Tree Easy Practice Subtree of Another Tree on LeetCode (opens in a new tab)
  9. 70 Binary Tree Level Order Traversal Medium Practice Binary Tree Level Order Traversal on LeetCode (opens in a new tab)
  10. 71 Binary Tree Right Side View Medium Practice Binary Tree Right Side View on LeetCode (opens in a new tab)
  11. 72 Binary Tree Zigzag Level Order Traversal Medium Practice Binary Tree Zigzag Level Order Traversal on LeetCode (opens in a new tab)
  12. 73 Validate Binary Search Tree Medium Practice Validate Binary Search Tree on LeetCode (opens in a new tab)
  13. 74 Kth Smallest Element in a BST Medium Practice Kth Smallest Element in a BST on LeetCode (opens in a new tab)
  14. 75 Lowest Common Ancestor of a Binary Search Tree Medium Practice Lowest Common Ancestor of a Binary Search Tree on LeetCode (opens in a new tab)
  15. 76 Lowest Common Ancestor of a Binary Tree Medium Practice Lowest Common Ancestor of a Binary Tree on LeetCode (opens in a new tab)
  16. 77 Construct Binary Tree from Preorder and Inorder Traversal Medium Practice Construct Binary Tree from Preorder and Inorder Traversal on LeetCode (opens in a new tab)
  17. 78 Binary Tree Maximum Path Sum Hard Practice Binary Tree Maximum Path Sum on LeetCode (opens in a new tab)
  18. 79 Serialize and Deserialize Binary Tree Hard Practice Serialize and Deserialize Binary Tree on LeetCode (opens in a new tab)

About the Trees problems

09 Heap / Priority Queue Always knowing the smallest or largest item: top-k questions, scheduling, and running medians. 0 / 5
  1. 80 Last Stone Weight Easy Practice Last Stone Weight on LeetCode (opens in a new tab)
  2. 81 Kth Largest Element in an Array Medium Practice Kth Largest Element in an Array on LeetCode (opens in a new tab)
  3. 82 K Closest Points to Origin Medium Practice K Closest Points to Origin on LeetCode (opens in a new tab)
  4. 83 Task Scheduler Medium Practice Task Scheduler on LeetCode (opens in a new tab)
  5. 84 Find Median from Data Stream Hard Practice Find Median from Data Stream on LeetCode (opens in a new tab)

About the Heap / Priority Queue problems

10 Backtracking Building every candidate answer one choice at a time, and undoing the choice to try the next: subsets, permutations, combinations and boards. 0 / 10
  1. 85 Subsets Medium Practice Subsets on LeetCode (opens in a new tab)
  2. 86 Subsets II Medium Practice Subsets II on LeetCode (opens in a new tab)
  3. 87 Permutations Medium Practice Permutations on LeetCode (opens in a new tab)
  4. 88 Combination Sum Medium Practice Combination Sum on LeetCode (opens in a new tab)
  5. 89 Combination Sum II Medium Practice Combination Sum II on LeetCode (opens in a new tab)
  6. 90 Letter Combinations of a Phone Number Medium Practice Letter Combinations of a Phone Number on LeetCode (opens in a new tab)
  7. 91 Generate Parentheses Medium Practice Generate Parentheses on LeetCode (opens in a new tab)
  8. 92 Word Search Medium Practice Word Search on LeetCode (opens in a new tab)
  9. 93 Palindrome Partitioning Medium Practice Palindrome Partitioning on LeetCode (opens in a new tab)
  10. 94 N-Queens Hard Practice N-Queens on LeetCode (opens in a new tab)

About the Backtracking problems

11 Tries Prefix trees: storing many words so that prefix lookups, wildcard searches and grid word hunts become fast. 0 / 3
  1. 95 Implement Trie (Prefix Tree) Medium Practice Implement Trie (Prefix Tree) on LeetCode (opens in a new tab)
  2. 96 Design Add and Search Words Data Structure Medium Practice Design Add and Search Words Data Structure on LeetCode (opens in a new tab)
  3. 97 Word Search II Hard Practice Word Search II on LeetCode (opens in a new tab)

About the Tries problems

12 Graphs Grids and networks: depth-first and breadth-first search, multi-source BFS, cycle detection and topological sort. 0 / 12
  1. 98 Flood Fill Easy Practice Flood Fill on LeetCode (opens in a new tab)
  2. 99 Number of Islands Medium Practice Number of Islands on LeetCode (opens in a new tab)
  3. 100 Max Area of Island Medium Practice Max Area of Island on LeetCode (opens in a new tab)
  4. 101 Clone Graph Medium Practice Clone Graph on LeetCode (opens in a new tab)
  5. 102 Rotting Oranges Medium Practice Rotting Oranges on LeetCode (opens in a new tab)
  6. 103 01 Matrix Medium Practice 01 Matrix on LeetCode (opens in a new tab)
  7. 104 Surrounded Regions Medium Practice Surrounded Regions on LeetCode (opens in a new tab)
  8. 105 Pacific Atlantic Water Flow Medium Practice Pacific Atlantic Water Flow on LeetCode (opens in a new tab)
  9. 106 Course Schedule Medium Practice Course Schedule on LeetCode (opens in a new tab)
  10. 107 Course Schedule II Medium Practice Course Schedule II on LeetCode (opens in a new tab)
  11. 108 Is Graph Bipartite? Medium Practice Is Graph Bipartite? on LeetCode (opens in a new tab)
  12. 109 Word Ladder Hard Practice Word Ladder on LeetCode (opens in a new tab)

About the Graphs problems

13 Advanced Graphs Union-Find, shortest paths with Dijkstra and Bellman-Ford, and minimum spanning trees. 0 / 5
  1. 110 Number of Provinces Medium Practice Number of Provinces on LeetCode (opens in a new tab)
  2. 111 Redundant Connection Medium Practice Redundant Connection on LeetCode (opens in a new tab)
  3. 112 Network Delay Time Medium Practice Network Delay Time on LeetCode (opens in a new tab)
  4. 113 Cheapest Flights Within K Stops Medium Practice Cheapest Flights Within K Stops on LeetCode (opens in a new tab)
  5. 114 Min Cost to Connect All Points Medium Practice Min Cost to Connect All Points on LeetCode (opens in a new tab)

About the Advanced Graphs problems

14 1-D Dynamic Programming Breaking a problem into overlapping subproblems along one dimension: from plain recursion, to memoization, to a few variables. 0 / 12
  1. 115 Climbing Stairs Easy Practice Climbing Stairs on LeetCode (opens in a new tab)
  2. 116 Min Cost Climbing Stairs Easy Practice Min Cost Climbing Stairs on LeetCode (opens in a new tab)
  3. 117 House Robber Medium Practice House Robber on LeetCode (opens in a new tab)
  4. 118 House Robber II Medium Practice House Robber II on LeetCode (opens in a new tab)
  5. 119 Coin Change Medium Practice Coin Change on LeetCode (opens in a new tab)
  6. 120 Maximum Product Subarray Medium Practice Maximum Product Subarray on LeetCode (opens in a new tab)
  7. 121 Word Break Medium Practice Word Break on LeetCode (opens in a new tab)
  8. 122 Decode Ways Medium Practice Decode Ways on LeetCode (opens in a new tab)
  9. 123 Longest Increasing Subsequence Medium Practice Longest Increasing Subsequence on LeetCode (opens in a new tab)
  10. 124 Partition Equal Subset Sum Medium Practice Partition Equal Subset Sum on LeetCode (opens in a new tab)
  11. 125 Longest Palindromic Substring Medium Practice Longest Palindromic Substring on LeetCode (opens in a new tab)
  12. 126 Palindromic Substrings Medium Practice Palindromic Substrings on LeetCode (opens in a new tab)

About the 1-D Dynamic Programming problems

15 2-D Dynamic Programming Tables indexed by two things at once: grid paths, two strings compared character by character, and knapsack-style choices. 0 / 8
  1. 127 Unique Paths Medium Practice Unique Paths on LeetCode (opens in a new tab)
  2. 128 Minimum Path Sum Medium Practice Minimum Path Sum on LeetCode (opens in a new tab)
  3. 129 Longest Common Subsequence Medium Practice Longest Common Subsequence on LeetCode (opens in a new tab)
  4. 130 Edit Distance Medium Practice Edit Distance on LeetCode (opens in a new tab)
  5. 131 Coin Change II Medium Practice Coin Change II on LeetCode (opens in a new tab)
  6. 132 Target Sum Medium Practice Target Sum on LeetCode (opens in a new tab)
  7. 133 Best Time to Buy and Sell Stock with Cooldown Medium Practice Best Time to Buy and Sell Stock with Cooldown on LeetCode (opens in a new tab)
  8. 134 Distinct Subsequences Hard Practice Distinct Subsequences on LeetCode (opens in a new tab)

About the 2-D Dynamic Programming problems

16 Greedy Making the locally best choice at each step, and being able to explain why that is safe. 0 / 6
  1. 135 Jump Game Medium Practice Jump Game on LeetCode (opens in a new tab)
  2. 136 Jump Game II Medium Practice Jump Game II on LeetCode (opens in a new tab)
  3. 137 Gas Station Medium Practice Gas Station on LeetCode (opens in a new tab)
  4. 138 Hand of Straights Medium Practice Hand of Straights on LeetCode (opens in a new tab)
  5. 139 Partition Labels Medium Practice Partition Labels on LeetCode (opens in a new tab)
  6. 140 Valid Parenthesis String Medium Practice Valid Parenthesis String on LeetCode (opens in a new tab)

About the Greedy problems

17 Intervals Ranges with a start and an end: sort them, then merge, insert or choose which to keep. 0 / 4
  1. 141 Merge Intervals Medium Practice Merge Intervals on LeetCode (opens in a new tab)
  2. 142 Insert Interval Medium Practice Insert Interval on LeetCode (opens in a new tab)
  3. 143 Non-overlapping Intervals Medium Practice Non-overlapping Intervals on LeetCode (opens in a new tab)
  4. 144 Minimum Number of Arrows to Burst Balloons Medium Practice Minimum Number of Arrows to Burst Balloons on LeetCode (opens in a new tab)

About the Intervals problems

18 Bit Manipulation & Math XOR tricks, counting and reversing bits, and fast exponentiation: short solutions that rely on one key fact. 0 / 7
  1. 145 Single Number Easy Practice Single Number on LeetCode (opens in a new tab)
  2. 146 Number of 1 Bits Easy Practice Number of 1 Bits on LeetCode (opens in a new tab)
  3. 147 Counting Bits Easy Practice Counting Bits on LeetCode (opens in a new tab)
  4. 148 Missing Number Easy Practice Missing Number on LeetCode (opens in a new tab)
  5. 149 Reverse Bits Easy Practice Reverse Bits on LeetCode (opens in a new tab)
  6. 150 Pow(x, n) Medium Practice Pow(x, n) on LeetCode (opens in a new tab)
  7. 151 Sum of Two Integers Medium Practice Sum of Two Integers on LeetCode (opens in a new tab)

About the Bit Manipulation & Math problems