Medium LeetCode Problems: All 1,579, With Python Solutions
Medium is where most interview questions actually sit. The technique is no longer stated — recognising which pattern applies is the problem, and the implementation is the easy half once you have.
The rating is LeetCode's own, carried through unchanged — we do not re-score anything. This library holds 1,579 Medium-rated problems, 1,191 of them with a complete Python solution, a worked example and complexity analysis.
The patterns behind medium problems
The six patterns with the most Medium-rated problems in this library. Working through a pattern beats working down a difficulty list, because the technique transfers and a difficulty band does not.
- Hash Map · 372 Medium problems — Trade memory for time: remember what you have seen so the second pass never happens.
- Math and Number Theory · 244 Medium problems — Find the closed form, the invariant, or the modular identity — and skip the loop entirely.
- Dynamic Programming · 243 Medium problems — Define a state, write the transition, and stop recomputing the same subproblem.
- Greedy · 234 Medium problems — Take the locally best option every time — when you can prove that never costs you later.
- Sorting · 227 Medium problems — Spend O(n log n) once to buy an ordering that makes the rest of the problem trivial.
- Depth-First Search · 214 Medium problems — Follow one path to its end before trying the next — the default way to explore a graph.
Medium problems
Showing the first 200 of 1,579 problems. Problems with a complete Python solution are listed first, then by ascending problem number.
| # | Problem | Difficulty | Topics |
|---|---|---|---|
| 2 | Add Two Numbers | Medium | Recursion, Linked List, Math |
| 3 | Longest Substring Without Repeating Characters | Medium | Hash Table, String, Sliding Window |
| 5 | Longest Palindromic Substring | Medium | Two Pointers, String, Dynamic Programming |
| 6 | Zigzag Conversion | Medium | String |
| 7 | Reverse Integer | Medium | Math |
| 8 | String to Integer (atoi) | Medium | String |
| 11 | Container With Most Water | Medium | Greedy, Array, Two Pointers |
| 12 | Integer to Roman | Medium | Hash Table, Math, String |
| 15 | 3Sum | Medium | Array, Two Pointers, Sorting |
| 16 | 3Sum Closest | Medium | Array, Two Pointers, Sorting |
| 17 | Letter Combinations of a Phone Number | Medium | Hash Table, String, Backtracking |
| 18 | 4Sum | Medium | Array, Two Pointers, Sorting |
| 19 | Remove Nth Node From End of List | Medium | Linked List, Two Pointers |
| 22 | Generate Parentheses | Medium | String, Dynamic Programming, Backtracking |
| 24 | Swap Nodes in Pairs | Medium | Recursion, Linked List |
| 29 | Divide Two Integers | Medium | Bit Manipulation, Math |
| 31 | Next Permutation | Medium | Array, Two Pointers |
| 33 | Search in Rotated Sorted Array | Medium | Array, Binary Search |
| 34 | Find First and Last Position of Element in Sorted Array | Medium | Array, Binary Search |
| 36 | Valid Sudoku | Medium | Array, Hash Table, Matrix |
| 38 | Count and Say | Medium | String |
| 39 | Combination Sum | Medium | Array, Backtracking |
| 40 | Combination Sum II | Medium | Array, Backtracking |
| 43 | Multiply Strings | Medium | Math, String, Simulation |
| 45 | Jump Game II | Medium | Greedy, Array, Dynamic Programming |
| 46 | Permutations | Medium | Array, Backtracking |
| 47 | Permutations II | Medium | Array, Backtracking, Sorting |
| 48 | Rotate Image | Medium | Array, Math, Matrix |
| 49 | Group Anagrams | Medium | Array, Hash Table, String +1 |
| 50 | Pow(x, n) | Medium | Recursion, Math |
| 53 | Maximum Subarray | Medium | Array, Divide and Conquer, Dynamic Programming |
| 54 | Spiral Matrix | Medium | Array, Matrix, Simulation |
| 55 | Jump Game | Medium | Greedy, Array, Dynamic Programming |
| 56 | Merge Intervals | Medium | Array, Sorting |
| 57 | Insert Interval | Medium | Array |
| 59 | Spiral Matrix II | Medium | Array, Matrix, Simulation |
| 61 | Rotate List | Medium | Linked List, Two Pointers |
| 62 | Unique Paths | Medium | Math, Dynamic Programming, Combinatorics |
| 63 | Unique Paths II | Medium | Array, Dynamic Programming, Matrix |
| 64 | Minimum Path Sum | Medium | Array, Dynamic Programming, Matrix |
| 71 | Simplify Path | Medium | Stack, String |
| 72 | Edit Distance | Medium | String, Dynamic Programming |
| 73 | Set Matrix Zeroes | Medium | Array, Hash Table, Matrix |
| 74 | Search a 2D Matrix | Medium | Array, Binary Search, Matrix |
| 75 | Sort Colors | Medium | Array, Two Pointers, Sorting |
| 77 | Combinations | Medium | Backtracking |
| 78 | Subsets | Medium | Bit Manipulation, Array, Backtracking |
| 79 | Word Search | Medium | Depth-First Search, Array, String +2 |
| 80 | Remove Duplicates from Sorted Array II | Medium | Array, Two Pointers |
| 81 | Search in Rotated Sorted Array II | Medium | Array, Binary Search |
| 82 | Remove Duplicates from Sorted List II | Medium | Linked List, Two Pointers |
| 86 | Partition List | Medium | Linked List, Two Pointers |
| 89 | Gray Code | Medium | Bit Manipulation, Math, Backtracking |
| 90 | Subsets II | Medium | Bit Manipulation, Array, Backtracking |
| 91 | Decode Ways | Medium | String, Dynamic Programming |
| 92 | Reverse Linked List II | Medium | Linked List |
| 93 | Restore IP Addresses | Medium | String, Backtracking |
| 95 | Unique Binary Search Trees II | Medium | Tree, Binary Search Tree, Dynamic Programming +2 |
| 96 | Unique Binary Search Trees | Medium | Tree, Binary Search Tree, Math +2 |
| 97 | Interleaving String | Medium | String, Dynamic Programming |
| 98 | Validate Binary Search Tree | Medium | Tree, Depth-First Search, Binary Search Tree +1 |
| 99 | Recover Binary Search Tree | Medium | Tree, Depth-First Search, Binary Search Tree +1 |
| 102 | Binary Tree Level Order Traversal | Medium | Tree, Breadth-First Search, Binary Tree |
| 103 | Binary Tree Zigzag Level Order Traversal | Medium | Tree, Breadth-First Search, Binary Tree |
| 105 | Construct Binary Tree from Preorder and Inorder Traversal | Medium | Tree, Array, Hash Table +2 |
| 106 | Construct Binary Tree from Inorder and Postorder Traversal | Medium | Tree, Array, Hash Table +2 |
| 107 | Binary Tree Level Order Traversal II | Medium | Tree, Breadth-First Search, Binary Tree |
| 109 | Convert Sorted List to Binary Search Tree | Medium | Tree, Binary Search Tree, Linked List +2 |
| 113 | Path Sum II | Medium | Tree, Depth-First Search, Backtracking +1 |
| 114 | Flatten Binary Tree to Linked List | Medium | Stack, Tree, Depth-First Search +2 |
| 116 | Populating Next Right Pointers in Each Node | Medium | Tree, Depth-First Search, Breadth-First Search +2 |
| 117 | Populating Next Right Pointers in Each Node II | Medium | Tree, Depth-First Search, Breadth-First Search +2 |
| 120 | Triangle | Medium | Array, Dynamic Programming |
| 122 | Best Time to Buy and Sell Stock II | Medium | Greedy, Array, Dynamic Programming |
| 128 | Longest Consecutive Sequence | Medium | Union Find, Array, Hash Table |
| 129 | Sum Root to Leaf Numbers | Medium | Tree, Depth-First Search, Binary Tree |
| 130 | Surrounded Regions | Medium | Depth-First Search, Breadth-First Search, Union Find +2 |
| 131 | Palindrome Partitioning | Medium | String, Dynamic Programming, Backtracking |
| 133 | Clone Graph | Medium | Depth-First Search, Breadth-First Search, Graph +1 |
| 134 | Gas Station | Medium | Greedy, Array |
| 137 | Single Number II | Medium | Bit Manipulation, Array |
| 138 | Copy List with Random Pointer | Medium | Hash Table, Linked List |
| 139 | Word Break | Medium | Trie, Memoization, Array +3 |
| 142 | Linked List Cycle II | Medium | Hash Table, Linked List, Two Pointers |
| 143 | Reorder List | Medium | Stack, Recursion, Linked List +1 |
| 146 | LRU Cache | Medium | Design, Hash Table, Linked List +1 |
| 147 | Insertion Sort List | Medium | Linked List, Sorting |
| 148 | Sort List | Medium | Linked List, Two Pointers, Divide and Conquer +2 |
| 150 | Evaluate Reverse Polish Notation | Medium | Stack, Array, Math |
| 151 | Reverse Words in a String | Medium | Two Pointers, String |
| 152 | Maximum Product Subarray | Medium | Array, Dynamic Programming |
| 153 | Find Minimum in Rotated Sorted Array | Medium | Array, Binary Search |
| 155 | Min Stack | Medium | Stack, Design |
| 162 | Find Peak Element | Medium | Array, Binary Search |
| 164 | Maximum Gap | Medium | Array, Bucket Sort, Radix Sort +1 |
| 165 | Compare Version Numbers | Medium | Two Pointers, String |
| 166 | Fraction to Recurring Decimal | Medium | Hash Table, Math, String |
| 167 | Two Sum II - Input Array Is Sorted | Medium | Array, Two Pointers, Binary Search |
| 172 | Factorial Trailing Zeroes | Medium | Math |
| 173 | Binary Search Tree Iterator | Medium | Stack, Tree, Design +3 |
| 176 | Second Highest Salary | Medium | Database |
| 177 | Nth Highest Salary | Medium | Database |
| 178 | Rank Scores | Medium | Database |
| 179 | Largest Number | Medium | Greedy, Array, String +1 |
| 180 | Consecutive Numbers | Medium | Database |
| 184 | Department Highest Salary | Medium | Database |
| 187 | Repeated DNA Sequences | Medium | Bit Manipulation, Hash Table, String +3 |
| 189 | Rotate Array | Medium | Array, Math, Two Pointers |
| 192 | Word Frequency | Medium | Shell |
| 194 | Transpose File | Medium | Shell |
| 198 | House Robber | Medium | Array, Dynamic Programming |
| 199 | Binary Tree Right Side View | Medium | Tree, Depth-First Search, Breadth-First Search +1 |
| 200 | Number of Islands | Medium | Depth-First Search, Breadth-First Search, Union Find +2 |
| 201 | Bitwise AND of Numbers Range | Medium | Bit Manipulation |
| 204 | Count Primes | Medium | Array, Math, Enumeration +1 |
| 207 | Course Schedule | Medium | Depth-First Search, Breadth-First Search, Graph +1 |
| 208 | Implement Trie (Prefix Tree) | Medium | Design, Trie, Hash Table +1 |
| 209 | Minimum Size Subarray Sum | Medium | Array, Binary Search, Prefix Sum +1 |
| 210 | Course Schedule II | Medium | Depth-First Search, Breadth-First Search, Graph +1 |
| 211 | Design Add and Search Words Data Structure | Medium | Depth-First Search, Design, Trie +1 |
| 213 | House Robber II | Medium | Array, Dynamic Programming |
| 215 | Kth Largest Element in an Array | Medium | Array, Divide and Conquer, Quickselect +2 |
| 216 | Combination Sum III | Medium | Array, Backtracking |
| 221 | Maximal Square | Medium | Array, Dynamic Programming, Matrix |
| 223 | Rectangle Area | Medium | Geometry, Math |
| 227 | Basic Calculator II | Medium | Stack, Math, String |
| 229 | Majority Element II | Medium | Array, Hash Table, Counting +1 |
| 230 | Kth Smallest Element in a BST | Medium | Tree, Depth-First Search, Binary Search Tree +1 |
| 235 | Lowest Common Ancestor of a Binary Search Tree | Medium | Tree, Depth-First Search, Binary Search Tree +1 |
| 236 | Lowest Common Ancestor of a Binary Tree | Medium | Tree, Depth-First Search, Binary Tree |
| 237 | Delete Node in a Linked List | Medium | Linked List |
| 238 | Product of Array Except Self | Medium | Array, Prefix Sum |
| 240 | Search a 2D Matrix II | Medium | Array, Binary Search, Divide and Conquer +1 |
| 241 | Different Ways to Add Parentheses | Medium | Recursion, Memoization, Math +2 |
| 260 | Single Number III | Medium | Bit Manipulation, Array |
| 264 | Ugly Number II | Medium | Hash Table, Math, Dynamic Programming +1 |
| 274 | H-Index | Medium | Array, Counting Sort, Sorting |
| 275 | H-Index II | Medium | Array, Binary Search |
| 279 | Perfect Squares | Medium | Breadth-First Search, Math, Dynamic Programming |
| 284 | Peeking Iterator | Medium | Design, Array, Iterator |
| 287 | Find the Duplicate Number | Medium | Bit Manipulation, Array, Two Pointers +1 |
| 289 | Game of Life | Medium | Array, Matrix, Simulation |
| 299 | Bulls and Cows | Medium | Hash Table, String, Counting |
| 300 | Longest Increasing Subsequence | Medium | Array, Binary Search, Dynamic Programming |
| 304 | Range Sum Query 2D - Immutable | Medium | Design, Array, Matrix +1 |
| 306 | Additive Number | Medium | String, Backtracking |
| 307 | Range Sum Query - Mutable | Medium | Design, Binary Indexed Tree, Segment Tree +2 |
| 309 | Best Time to Buy and Sell Stock with Cooldown | Medium | Array, Dynamic Programming |
| 310 | Minimum Height Trees | Medium | Depth-First Search, Breadth-First Search, Graph +1 |
| 313 | Super Ugly Number | Medium | Array, Math, Dynamic Programming |
| 316 | Remove Duplicate Letters | Medium | Stack, Greedy, String +1 |
| 318 | Maximum Product of Word Lengths | Medium | Bit Manipulation, Array, String |
| 319 | Bulb Switcher | Medium | Brainteaser, Math |
| 322 | Coin Change | Medium | Breadth-First Search, Array, Dynamic Programming |
| 324 | Wiggle Sort II | Medium | Greedy, Array, Divide and Conquer +2 |
| 328 | Odd Even Linked List | Medium | Linked List |
| 331 | Verify Preorder Serialization of a Binary Tree | Medium | Stack, Tree, String +1 |
| 334 | Increasing Triplet Subsequence | Medium | Greedy, Array |
| 337 | House Robber III | Medium | Tree, Depth-First Search, Dynamic Programming +1 |
| 341 | Flatten Nested List Iterator | Medium | Stack, Tree, Depth-First Search +3 |
| 343 | Integer Break | Medium | Math, Dynamic Programming |
| 347 | Top K Frequent Elements | Medium | Array, Hash Table, Divide and Conquer +5 |
| 355 | Design Twitter | Medium | Design, Hash Table, Linked List +1 |
| 357 | Count Numbers with Unique Digits | Medium | Math, Dynamic Programming, Backtracking |
| 365 | Water and Jug Problem | Medium | Depth-First Search, Breadth-First Search, Math |
| 368 | Largest Divisible Subset | Medium | Array, Math, Dynamic Programming +1 |
| 371 | Sum of Two Integers | Medium | Bit Manipulation, Math |
| 372 | Super Pow | Medium | Math, Divide and Conquer |
| 373 | Find K Pairs with Smallest Sums | Medium | Array, Heap (Priority Queue) |
| 375 | Guess Number Higher or Lower II | Medium | Math, Dynamic Programming, Game Theory |
| 376 | Wiggle Subsequence | Medium | Greedy, Array, Dynamic Programming |
| 377 | Combination Sum IV | Medium | Array, Dynamic Programming |
| 378 | Kth Smallest Element in a Sorted Matrix | Medium | Array, Binary Search, Matrix +2 |
| 380 | Insert Delete GetRandom O(1) | Medium | Design, Array, Hash Table +2 |
| 382 | Linked List Random Node | Medium | Reservoir Sampling, Linked List, Math +1 |
| 384 | Shuffle an Array | Medium | Design, Array, Math +1 |
| 385 | Mini Parser | Medium | Stack, Depth-First Search, String |
| 386 | Lexicographical Numbers | Medium | Depth-First Search, Trie |
| 388 | Longest Absolute File Path | Medium | Stack, Depth-First Search, String |
| 390 | Elimination Game | Medium | Recursion, Math |
| 393 | UTF-8 Validation | Medium | Bit Manipulation, Array |
| 394 | Decode String | Medium | Stack, Recursion, String |
| 395 | Longest Substring with At Least K Repeating Characters | Medium | Hash Table, String, Divide and Conquer +1 |
| 396 | Rotate Function | Medium | Array, Math, Dynamic Programming |
| 397 | Integer Replacement | Medium | Greedy, Bit Manipulation, Memoization +1 |
| 398 | Random Pick Index | Medium | Reservoir Sampling, Hash Table, Math +1 |
| 399 | Evaluate Division | Medium | Depth-First Search, Breadth-First Search, Union Find +4 |
| 400 | Nth Digit | Medium | Math, Binary Search |
| 402 | Remove K Digits | Medium | Stack, Greedy, String +1 |
| 406 | Queue Reconstruction by Height | Medium | Binary Indexed Tree, Segment Tree, Array +1 |
| 413 | Arithmetic Slices | Medium | Array, Dynamic Programming, Sliding Window |
| 416 | Partition Equal Subset Sum | Medium | Array, Dynamic Programming |
| 417 | Pacific Atlantic Water Flow | Medium | Depth-First Search, Breadth-First Search, Array +1 |
| 419 | Battleships in a Board | Medium | Depth-First Search, Array, Matrix |
| 421 | Maximum XOR of Two Numbers in an Array | Medium | Bit Manipulation, Trie, Array +1 |
| 423 | Reconstruct Original Digits from English | Medium | Hash Table, Math, String |
| 424 | Longest Repeating Character Replacement | Medium | Hash Table, String, Sliding Window |
| 427 | Construct Quad Tree | Medium | Tree, Array, Divide and Conquer +1 |
| 429 | N-ary Tree Level Order Traversal | Medium | Tree, Breadth-First Search |
| 430 | Flatten a Multilevel Doubly Linked List | Medium | Depth-First Search, Linked List, Doubly-Linked List |
Keep exploring
Everything at once: the full LeetCode problem list.
A medium problem, live, with someone watching
Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.