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
01 Arrays & Hashing Where every interview starts: scanning arrays, counting with hash maps and sets, and prefix sums. 0 / 15
- 1 Two Sum Easy Has notes Practice Two Sum on LeetCode (opens in a new tab)
- 2 Contains Duplicate Easy Has notes Practice Contains Duplicate on LeetCode (opens in a new tab)
- 3 Valid Anagram Easy Has notes Practice Valid Anagram on LeetCode (opens in a new tab)
- 4 Best Time to Buy and Sell Stock Easy Has notes Practice Best Time to Buy and Sell Stock on LeetCode (opens in a new tab)
- 5 Majority Element Easy Has notes Practice Majority Element on LeetCode (opens in a new tab)
- 6 Move Zeroes Easy Has notes Practice Move Zeroes on LeetCode (opens in a new tab)
- 7 Merge Sorted Array Easy Has notes Practice Merge Sorted Array on LeetCode (opens in a new tab)
- 8 Group Anagrams Medium Has notes Practice Group Anagrams on LeetCode (opens in a new tab)
- 9 Top K Frequent Elements Medium Has notes Practice Top K Frequent Elements on LeetCode (opens in a new tab)
- 10 Product of Array Except Self Medium Has notes Practice Product of Array Except Self on LeetCode (opens in a new tab)
- 11 Longest Consecutive Sequence Medium Has notes Practice Longest Consecutive Sequence on LeetCode (opens in a new tab)
- 12 Maximum Subarray Medium Has notes Practice Maximum Subarray on LeetCode (opens in a new tab)
- 13 Subarray Sum Equals K Medium Has notes Practice Subarray Sum Equals K on LeetCode (opens in a new tab)
- 14 Sort Colors Medium Has notes Practice Sort Colors on LeetCode (opens in a new tab)
- 15 Next Permutation Medium Has notes Practice Next Permutation on LeetCode (opens in a new tab)
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
- 16 Valid Palindrome Easy Has notes Practice Valid Palindrome on LeetCode (opens in a new tab)
- 17 Remove Duplicates from Sorted Array Easy Has notes Practice Remove Duplicates from Sorted Array on LeetCode (opens in a new tab)
- 18 Two Sum II – Input Array Is Sorted Medium Has notes Practice Two Sum II – Input Array Is Sorted on LeetCode (opens in a new tab)
- 19 3Sum Medium Has notes Practice 3Sum on LeetCode (opens in a new tab)
- 20 Container With Most Water Medium Has notes Practice Container With Most Water on LeetCode (opens in a new tab)
- 21 Trapping Rain Water Hard Has notes Practice Trapping Rain Water on LeetCode (opens in a new tab)
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
- 22 Longest Substring Without Repeating Characters Medium Has notes Practice Longest Substring Without Repeating Characters on LeetCode (opens in a new tab)
- 23 Longest Repeating Character Replacement Medium Has notes Practice Longest Repeating Character Replacement on LeetCode (opens in a new tab)
- 24 Permutation in String Medium Has notes Practice Permutation in String on LeetCode (opens in a new tab)
- 25 Max Consecutive Ones III Medium Has notes Practice Max Consecutive Ones III on LeetCode (opens in a new tab)
- 26 Minimum Window Substring Hard Has notes Practice Minimum Window Substring on LeetCode (opens in a new tab)
- 27 Sliding Window Maximum Hard Has notes Practice Sliding Window Maximum on LeetCode (opens in a new tab)
04 Matrix 2D arrays: walking rows and columns, rotating and transforming in place, and using the grid itself as storage. 0 / 5
- 28 Pascal’s Triangle Easy Has notes Practice Pascal’s Triangle on LeetCode (opens in a new tab)
- 29 Set Matrix Zeroes Medium Has notes Practice Set Matrix Zeroes on LeetCode (opens in a new tab)
- 30 Rotate Image Medium Has notes Practice Rotate Image on LeetCode (opens in a new tab)
- 31 Spiral Matrix Medium Has notes Practice Spiral Matrix on LeetCode (opens in a new tab)
- 32 Valid Sudoku Medium Has notes Practice Valid Sudoku on LeetCode (opens in a new tab)
05 Stack Last in, first out: matching brackets, evaluating expressions, and monotonic stacks for "next greater" questions. 0 / 7
- 33 Valid Parentheses Easy Has notes Practice Valid Parentheses on LeetCode (opens in a new tab)
- 34 Next Greater Element I Easy Has notes Practice Next Greater Element I on LeetCode (opens in a new tab)
- 35 Min Stack Medium Has notes Practice Min Stack on LeetCode (opens in a new tab)
- 36 Evaluate Reverse Polish Notation Medium Has notes Practice Evaluate Reverse Polish Notation on LeetCode (opens in a new tab)
- 37 Daily Temperatures Medium Has notes Practice Daily Temperatures on LeetCode (opens in a new tab)
- 38 Asteroid Collision Medium Has notes Practice Asteroid Collision on LeetCode (opens in a new tab)
- 39 Largest Rectangle in Histogram Hard Has notes Practice Largest Rectangle in Histogram on LeetCode (opens in a new tab)
06 Binary Search Halving the search space each step: sorted arrays, rotated arrays, and searching over the answer itself. 0 / 8
- 40 Binary Search Easy Has notes Practice Binary Search on LeetCode (opens in a new tab)
- 41 Search a 2D Matrix Medium Has notes Practice Search a 2D Matrix on LeetCode (opens in a new tab)
- 42 Find First and Last Position of Element in Sorted Array Medium Has notes Practice Find First and Last Position of Element in Sorted Array on LeetCode (opens in a new tab)
- 43 Find Peak Element Medium Has notes Practice Find Peak Element on LeetCode (opens in a new tab)
- 44 Koko Eating Bananas Medium Has notes Practice Koko Eating Bananas on LeetCode (opens in a new tab)
- 45 Find Minimum in Rotated Sorted Array Medium Has notes Practice Find Minimum in Rotated Sorted Array on LeetCode (opens in a new tab)
- 46 Search in Rotated Sorted Array Medium Has notes Practice Search in Rotated Sorted Array on LeetCode (opens in a new tab)
- 47 Median of Two Sorted Arrays Hard Has notes Practice Median of Two Sorted Arrays on LeetCode (opens in a new tab)
07 Linked List Pointer surgery: reversing, merging, fast and slow pointers, and dummy heads that remove edge cases. 0 / 14
- 48 Reverse Linked List Easy Has notes Practice Reverse Linked List on LeetCode (opens in a new tab)
- 49 Merge Two Sorted Lists Easy Has notes Practice Merge Two Sorted Lists on LeetCode (opens in a new tab)
- 50 Linked List Cycle Easy Has notes Practice Linked List Cycle on LeetCode (opens in a new tab)
- 51 Middle of the Linked List Easy Has notes Practice Middle of the Linked List on LeetCode (opens in a new tab)
- 52 Palindrome Linked List Easy Has notes Practice Palindrome Linked List on LeetCode (opens in a new tab)
- 53 Intersection of Two Linked Lists Easy Has notes Practice Intersection of Two Linked Lists on LeetCode (opens in a new tab)
- 54 Remove Nth Node From End of List Medium Has notes Practice Remove Nth Node From End of List on LeetCode (opens in a new tab)
- 55 Linked List Cycle II Medium Has notes Practice Linked List Cycle II on LeetCode (opens in a new tab)
- 56 Reorder List Medium Has notes Practice Reorder List on LeetCode (opens in a new tab)
- 57 Add Two Numbers Medium Has notes Practice Add Two Numbers on LeetCode (opens in a new tab)
- 58 Copy List with Random Pointer Medium Has notes Practice Copy List with Random Pointer on LeetCode (opens in a new tab)
- 59 LRU Cache Medium Has notes Practice LRU Cache on LeetCode (opens in a new tab)
- 60 Merge k Sorted Lists Hard Has notes Practice Merge k Sorted Lists on LeetCode (opens in a new tab)
- 61 Reverse Nodes in k-Group Hard Has notes Practice Reverse Nodes in k-Group on LeetCode (opens in a new tab)
08 Trees Binary trees and binary search trees: recursion, depth-first and breadth-first traversal, and passing information up and down. 0 / 18
- 62 Binary Tree Inorder Traversal Easy Has notes Practice Binary Tree Inorder Traversal on LeetCode (opens in a new tab)
- 63 Maximum Depth of Binary Tree Easy Has notes Practice Maximum Depth of Binary Tree on LeetCode (opens in a new tab)
- 64 Invert Binary Tree Easy Has notes Practice Invert Binary Tree on LeetCode (opens in a new tab)
- 65 Same Tree Easy Has notes Practice Same Tree on LeetCode (opens in a new tab)
- 66 Symmetric Tree Easy Has notes Practice Symmetric Tree on LeetCode (opens in a new tab)
- 67 Diameter of Binary Tree Easy Has notes Practice Diameter of Binary Tree on LeetCode (opens in a new tab)
- 68 Balanced Binary Tree Easy Has notes Practice Balanced Binary Tree on LeetCode (opens in a new tab)
- 69 Subtree of Another Tree Easy Has notes Practice Subtree of Another Tree on LeetCode (opens in a new tab)
- 70 Binary Tree Level Order Traversal Medium Has notes Practice Binary Tree Level Order Traversal on LeetCode (opens in a new tab)
- 71 Binary Tree Right Side View Medium Has notes Practice Binary Tree Right Side View on LeetCode (opens in a new tab)
- 72 Binary Tree Zigzag Level Order Traversal Medium Has notes Practice Binary Tree Zigzag Level Order Traversal on LeetCode (opens in a new tab)
- 73 Validate Binary Search Tree Medium Has notes Practice Validate Binary Search Tree on LeetCode (opens in a new tab)
- 74 Kth Smallest Element in a BST Medium Has notes Practice Kth Smallest Element in a BST on LeetCode (opens in a new tab)
- 75 Lowest Common Ancestor of a Binary Search Tree Medium Has notes Practice Lowest Common Ancestor of a Binary Search Tree on LeetCode (opens in a new tab)
- 76 Lowest Common Ancestor of a Binary Tree Medium Has notes Practice Lowest Common Ancestor of a Binary Tree on LeetCode (opens in a new tab)
- 77 Construct Binary Tree from Preorder and Inorder Traversal Medium Has notes Practice Construct Binary Tree from Preorder and Inorder Traversal on LeetCode (opens in a new tab)
- 78 Binary Tree Maximum Path Sum Hard Has notes Practice Binary Tree Maximum Path Sum on LeetCode (opens in a new tab)
- 79 Serialize and Deserialize Binary Tree Hard Has notes Practice Serialize and Deserialize Binary Tree on LeetCode (opens in a new tab)
09 Heap / Priority Queue Always knowing the smallest or largest item: top-k questions, scheduling, and running medians. 0 / 5
- 80 Last Stone Weight Easy Has notes Practice Last Stone Weight on LeetCode (opens in a new tab)
- 81 Kth Largest Element in an Array Medium Has notes Practice Kth Largest Element in an Array on LeetCode (opens in a new tab)
- 82 K Closest Points to Origin Medium Has notes Practice K Closest Points to Origin on LeetCode (opens in a new tab)
- 83 Task Scheduler Medium Has notes Practice Task Scheduler on LeetCode (opens in a new tab)
- 84 Find Median from Data Stream Hard Has notes Practice Find Median from Data Stream on LeetCode (opens in a new tab)
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
- 85 Subsets Medium Has notes Practice Subsets on LeetCode (opens in a new tab)
- 86 Subsets II Medium Has notes Practice Subsets II on LeetCode (opens in a new tab)
- 87 Permutations Medium Has notes Practice Permutations on LeetCode (opens in a new tab)
- 88 Combination Sum Medium Has notes Practice Combination Sum on LeetCode (opens in a new tab)
- 89 Combination Sum II Medium Has notes Practice Combination Sum II on LeetCode (opens in a new tab)
- 90 Letter Combinations of a Phone Number Medium Has notes Practice Letter Combinations of a Phone Number on LeetCode (opens in a new tab)
- 91 Generate Parentheses Medium Has notes Practice Generate Parentheses on LeetCode (opens in a new tab)
- 92 Word Search Medium Has notes Practice Word Search on LeetCode (opens in a new tab)
- 93 Palindrome Partitioning Medium Has notes Practice Palindrome Partitioning on LeetCode (opens in a new tab)
- 94 N-Queens Hard Has notes Practice N-Queens on LeetCode (opens in a new tab)
11 Tries Prefix trees: storing many words so that prefix lookups, wildcard searches and grid word hunts become fast. 0 / 3
- 95 Implement Trie (Prefix Tree) Medium Has notes Practice Implement Trie (Prefix Tree) on LeetCode (opens in a new tab)
- 96 Design Add and Search Words Data Structure Medium Has notes Practice Design Add and Search Words Data Structure on LeetCode (opens in a new tab)
- 97 Word Search II Hard Has notes Practice Word Search II on LeetCode (opens in a new tab)
12 Graphs Grids and networks: depth-first and breadth-first search, multi-source BFS, cycle detection and topological sort. 0 / 12
- 98 Flood Fill Easy Has notes Practice Flood Fill on LeetCode (opens in a new tab)
- 99 Number of Islands Medium Has notes Practice Number of Islands on LeetCode (opens in a new tab)
- 100 Max Area of Island Medium Has notes Practice Max Area of Island on LeetCode (opens in a new tab)
- 101 Clone Graph Medium Has notes Practice Clone Graph on LeetCode (opens in a new tab)
- 102 Rotting Oranges Medium Has notes Practice Rotting Oranges on LeetCode (opens in a new tab)
- 103 01 Matrix Medium Has notes Practice 01 Matrix on LeetCode (opens in a new tab)
- 104 Surrounded Regions Medium Has notes Practice Surrounded Regions on LeetCode (opens in a new tab)
- 105 Pacific Atlantic Water Flow Medium Has notes Practice Pacific Atlantic Water Flow on LeetCode (opens in a new tab)
- 106 Course Schedule Medium Has notes Practice Course Schedule on LeetCode (opens in a new tab)
- 107 Course Schedule II Medium Has notes Practice Course Schedule II on LeetCode (opens in a new tab)
- 108 Is Graph Bipartite? Medium Has notes Practice Is Graph Bipartite? on LeetCode (opens in a new tab)
- 109 Word Ladder Hard Has notes Practice Word Ladder on LeetCode (opens in a new tab)
13 Advanced Graphs Union-Find, shortest paths with Dijkstra and Bellman-Ford, and minimum spanning trees. 0 / 5
- 110 Number of Provinces Medium Has notes Practice Number of Provinces on LeetCode (opens in a new tab)
- 111 Redundant Connection Medium Has notes Practice Redundant Connection on LeetCode (opens in a new tab)
- 112 Network Delay Time Medium Has notes Practice Network Delay Time on LeetCode (opens in a new tab)
- 113 Cheapest Flights Within K Stops Medium Has notes Practice Cheapest Flights Within K Stops on LeetCode (opens in a new tab)
- 114 Min Cost to Connect All Points Medium Has notes Practice Min Cost to Connect All Points on LeetCode (opens in a new tab)
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
- 115 Climbing Stairs Easy Has notes Practice Climbing Stairs on LeetCode (opens in a new tab)
- 116 Min Cost Climbing Stairs Easy Has notes Practice Min Cost Climbing Stairs on LeetCode (opens in a new tab)
- 117 House Robber Medium Has notes Practice House Robber on LeetCode (opens in a new tab)
- 118 House Robber II Medium Has notes Practice House Robber II on LeetCode (opens in a new tab)
- 119 Coin Change Medium Has notes Practice Coin Change on LeetCode (opens in a new tab)
- 120 Maximum Product Subarray Medium Has notes Practice Maximum Product Subarray on LeetCode (opens in a new tab)
- 121 Word Break Medium Has notes Practice Word Break on LeetCode (opens in a new tab)
- 122 Decode Ways Medium Has notes Practice Decode Ways on LeetCode (opens in a new tab)
- 123 Longest Increasing Subsequence Medium Has notes Practice Longest Increasing Subsequence on LeetCode (opens in a new tab)
- 124 Partition Equal Subset Sum Medium Has notes Practice Partition Equal Subset Sum on LeetCode (opens in a new tab)
- 125 Longest Palindromic Substring Medium Has notes Practice Longest Palindromic Substring on LeetCode (opens in a new tab)
- 126 Palindromic Substrings Medium Has notes Practice Palindromic Substrings on LeetCode (opens in a new tab)
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
- 127 Unique Paths Medium Has notes Practice Unique Paths on LeetCode (opens in a new tab)
- 128 Minimum Path Sum Medium Has notes Practice Minimum Path Sum on LeetCode (opens in a new tab)
- 129 Longest Common Subsequence Medium Has notes Practice Longest Common Subsequence on LeetCode (opens in a new tab)
- 130 Edit Distance Medium Has notes Practice Edit Distance on LeetCode (opens in a new tab)
- 131 Coin Change II Medium Has notes Practice Coin Change II on LeetCode (opens in a new tab)
- 132 Target Sum Medium Has notes Practice Target Sum on LeetCode (opens in a new tab)
- 133 Best Time to Buy and Sell Stock with Cooldown Medium Has notes Practice Best Time to Buy and Sell Stock with Cooldown on LeetCode (opens in a new tab)
- 134 Distinct Subsequences Hard Has notes Practice Distinct Subsequences on LeetCode (opens in a new tab)
16 Greedy Making the locally best choice at each step, and being able to explain why that is safe. 0 / 6
- 135 Jump Game Medium Has notes Practice Jump Game on LeetCode (opens in a new tab)
- 136 Jump Game II Medium Has notes Practice Jump Game II on LeetCode (opens in a new tab)
- 137 Gas Station Medium Has notes Practice Gas Station on LeetCode (opens in a new tab)
- 138 Hand of Straights Medium Has notes Practice Hand of Straights on LeetCode (opens in a new tab)
- 139 Partition Labels Medium Has notes Practice Partition Labels on LeetCode (opens in a new tab)
- 140 Valid Parenthesis String Medium Has notes Practice Valid Parenthesis String on LeetCode (opens in a new tab)
17 Intervals Ranges with a start and an end: sort them, then merge, insert or choose which to keep. 0 / 4
- 141 Merge Intervals Medium Has notes Practice Merge Intervals on LeetCode (opens in a new tab)
- 142 Insert Interval Medium Has notes Practice Insert Interval on LeetCode (opens in a new tab)
- 143 Non-overlapping Intervals Medium Has notes Practice Non-overlapping Intervals on LeetCode (opens in a new tab)
- 144 Minimum Number of Arrows to Burst Balloons Medium Has notes Practice Minimum Number of Arrows to Burst Balloons on LeetCode (opens in a new tab)
18 Bit Manipulation & Math XOR tricks, counting and reversing bits, and fast exponentiation: short solutions that rely on one key fact. 0 / 7
- 145 Single Number Easy Has notes Practice Single Number on LeetCode (opens in a new tab)
- 146 Number of 1 Bits Easy Has notes Practice Number of 1 Bits on LeetCode (opens in a new tab)
- 147 Counting Bits Easy Has notes Practice Counting Bits on LeetCode (opens in a new tab)
- 148 Missing Number Easy Has notes Practice Missing Number on LeetCode (opens in a new tab)
- 149 Reverse Bits Easy Has notes Practice Reverse Bits on LeetCode (opens in a new tab)
- 150 Pow(x, n) Medium Has notes Practice Pow(x, n) on LeetCode (opens in a new tab)
- 151 Sum of Two Integers Medium Has notes Practice Sum of Two Integers on LeetCode (opens in a new tab)
No problems match these filters.