Let's grind LeetCode!
Solutions and visual explanations to LeetCode problems, fully tested using official sample test cases that are not locked behind a paywall.
Concepts
Problems
Legend
Unofficial listing
Grind 75
- Week 1
- Week 2
- First Bad Version
- Ransom Note
- Climbing Stairs
- Longest Palindrome
- Reverse Linked List
- Majority Element
- Add Binary
- Diameter of Binary Tree
- Middle of the Linked List
- Maximum Depth of Binary Tree
- Contains Duplicate
- Maximum Subarray
- Week 3
- Insert Interval
- 01 Matrix
- K Closest Points to Origin
- Longest Substring Without Repeating Characters
- Three Sum
- Binary Tree Level Order Traversal
- Clone Graph
- Evaluate Reverse Polish Notation
- Week 4
- Course Schedule
- Implement Trie (Prefix Tree)
- Coin Change
- Product of Array Except Self
- Min Stack
- Validate Binary Search Tree
- Number of Islands
- Rotting Oranges
- Week 5
- Search in Rotated Sorted Array
- Combination Sum
- Permutations
- Merge Intervals
- Lowest Common Ancestor of a Binary Tree
- Time Based Key-Value Store
- Accounts Merge
- Sort Colors
- Week 6
- Word Break
- Partition Equal Subset Sum
- String to Integer (atoi)
- Spiral Matrix
- Subsets
- Binary Tree Right Side View
- Longest Palindromic Substring
- Unique Paths
- Construct Binary Tree from Preorder and Inorder Traversal
- Week 7
- Container With Most Water
- Letter Combinations of a Phone Number
- Word Search
- Find All Anagrams in a String
- Minimum Height Trees
- Task Scheduler
- LRU Cache
- Week 8
- Kth Smallest Element in a BST
- Minimum Window Substring
- Serialize and Deserialize Binary Tree
- Trapping Rain Water
- Find Median from Data Stream
- Word Ladder
- Basic Calculator
- Maximum Profit in Job Scheduling
- Merge k Sorted Lists
- Largest Rectangle in Histogram
Neetcode 150
- Arrays & Hashing
- Contains Duplicate
- Valid Anagram
- Two Sum
- Group Anagrams
- Top K Frequent Elements
Encode and Decode Strings- Product of Array Except Self
- Valid Sudoku
- Longest Consecutive Sequence
- Two Pointers
- Valid Palindrome
- Two Sum II - Input Array Is Sorted
- Three Sum
- Container With Most Water
- Trapping Rain Water
- Sliding Window
- Best Time to Buy and Sell Stock
- Longest Substring Without Repeating Characters
- Longest Repeating Character Replacement
- Permutation in String
- Minimum Window Substring
- Sliding Window Maximum
- Stack
- Valid Parentheses
- Min Stack
- Evaluate Reverse Polish Notation
- Generate Parentheses
- Daily Temperatures
- Car Fleet
- Largest Rectangle in Histogram
- Binary Search
- Binary Search
- Search in Rotated Sorted Array
- Find Minimum in Rotated Sorted Array
- Search a 2D Matrix
- Search a 2D Matrix II
- Kth Smallest Element in a Sorted Matrix
- Find Peak Element
- Peak Index in a Mountain Array
- Linked List
- Reverse Linked List
- Merge Two Sorted Lists
- Linked List Cycle
- Reorder List
- Remove Nth Node From End of List
- Copy List with Random Pointer
- Add Two Numbers
- Find The Duplicate Number
- LRU Cache
- Merge k Sorted Lists
- Reverse Nodes in K-Group
- Trees
- Invert Binary Tree
- Maximum Depth of Binary Tree
- Diameter of Binary Tree
- Balanced Binary Tree
- Same Tree
- Subtree of Another Tree
- Lowest Common Ancestor of a Binary Search Tree
- Binary Tree Level Order Traversal
- Binary Tree Right Side View
- Count Good Nodes in Binary Tree
- Validate Binary Search Tree
- Kth Smallest Element in a BST
- Construct Binary Tree from Preorder and Inorder Traversal
- Binary Tree Maximum Path Sum
- Serialize and Deserialize Binary Tree
- Heap / Priority Queue
- Kth Largest Element in a Stream
- Last Stone Weight
- K Closest Points to Origin
- Kth Largest Element in an Array
- Task Scheduler
- Design Twitter
- Find Median from Data Stream
- Backtracking
- Subsets
- Combination Sum
- Combination Sum II
- Permutations
- Subsets II
- Word Search
- Palindrome Partitioning
- Letter Combinations of a Phone Number
- N-Queens
- Tries
- Implement Trie Prefix Tree
- Design Add and Search Words Data Structure
- Word Search II
- Graphs
- Number of Islands
- Max Area of Island
- Clone Graph
Walls and Gates- Rotting Oranges
- Pacific Atlantic Water Flow
- Surrounded Regions
- Course Schedule
- Course Schedule II
Graph Valid TreeNumber of Connected Components in an Undirected Graph- Redundant Connection
- Word Ladder
- Advanced Graphs
- Network Delay Time
- Reconstruct Itinerary
- Min Cost to Connect All Points
- Swim in Rising Water
Alien Dictionary- Cheapest Flights Within K Stops
- 1-D Dynamic Programming
- Climbing Stairs
- Min Cost Climbing Stairs
- House Robber
- House Robber II
- Longest Palindromic Substring
- Palindromic Substrings
- Decode Ways
- Coin Change
- Maximum Product Subarray
- Word Break
- Longest Increasing Subsequence
- Partition Equal Subset Sum
- 2-D Dynamic Programming
- Unique Paths
- Longest Common Subsequence
- Best Time to Buy And Sell Stock With Cooldown
- Coin Change II
- Target Sum
- Interleaving String
- Longest Increasing Path In a Matrix
- Distinct Subsequences
- Edit Distance
- Burst Balloons
- Regular Expression Matching
- Greedy
- Maximum Subarray
- Jump Game
- Jump Game II
- Gas Station
- Hand of Straights
- Merge Triplets to Form Target Triplet
- Partition Labels
- Valid Parenthesis String
- Intervals
- Insert Interval
- Merge Intervals
- Non Overlapping Intervals
Meeting RoomsMeeting Rooms II- Minimum Interval to Include Each Query
- Math & Geometry
- Rotate Image
- Spiral Matrix
- Set Matrix Zeroes
- Happy Number
- Plus One
- Pow(x, n)
- Multiply Strings
- Detect Squares
- Bit Manipulation
- Single Number
- Number of 1 Bits
- Counting Bits
- Reverse Bits
- Missing Number
- Sum of Two Integers
- Reverse Integer
Official listing
| 1-50 | 51-100 |
|---|---|
| 1. Two Sum | 51. N-Queens |
| 2. Add Two Numbers | 52. N-Queens II |
| 3. Longest Substring Without Repeating Characters | 53. Maximum Subarray |
| 4. Median of Two Sorted Arrays | 54. Spiral Matrix |
| 5. Longest Palindromic Substring | 55. Jump Game |
| 6. Zigzag Conversion | 56. Merge Intervals |
| 7. Reverse Integer | 57. Insert Interval |
| 8. String to Integer (atoi) | 58. Length of Last Word |
| 9. Palindrome Number | 59. Spiral Matrix II |
| 10. Regular Expression Matching | 60. Permutation Sequence |
| 11. Container With Most Water | 61. Rotate List |
| 12. Integer to Roman | 62. Unique Paths |
| 13. Roman to Integer | 63. Unique Paths II |
| 14. Longest Common Prefix | 64. Minimum Path Sum |
| 15. Three Sum | 65. Valid Number |
| 16. Three Sum Closest | 66. Plus One |
| 17. Letter Combinations of a Phone Number | 67. Add Binary |
| 18. Four Sum | 68. Text Justification |
| 19. Remove Nth Node From End of List | 69. Sqrt(x) |
| 20. Valid Parentheses | 70. Climbing Stairs |
| 21. Merge Two Sorted Lists | 71. Simplify Path |
| 22. Generate Parentheses | 72. Edit Distance |
| 23. Merge k Sorted Lists | 73. Set Matrix Zeroes |
| 24. Swap Nodes in Pairs | 74. Search a 2D Matrix |
| 25. Reverse Nodes in k-Group | 75. Sort Colors |
| 26. Remove Duplicates from Sorted Array | 76. Minimum Window Substring |
| 27. Remove Element | 77. Combinations |
| 28. Find the Index of the First Occurrence in a String | 78. Subsets |
| 29. Divide Two Integers | 79. Word Search |
| 30. Substring with Concatenation of All Words | 80. Remove Duplicates from Sorted Array II |
| 31. Next Permutation | 81. Search in Rotated Sorted Array II |
| 32. Longest Valid Parentheses | 82. Remove Duplicates from Sorted List II |
| 33. Search in Rotated Sorted Array | 83. Remove Duplicates from Sorted List |
| 34. Find First and Last Position of Element in Sorted Array | 84. Largest Rectangle in Histogram |
| 35. Search Insert Position | 85. Maximal Rectangle |
| 36. Valid Sudoku | 86. Partition List |
| 37. Sudoku Solver | 87. Scramble String |
| 38. Count and Say | 88. Merge Sorted Array |
| 39. Combination Sum | 89. Gray Code |
| 40. Combination Sum II | 90. Subsets II |
| 41. First Missing Positive | 91. Decode Ways |
| 42. Trapping Rain Water | 92. Reverse Linked List II |
| 43. Multiply Strings | 93. Restore IP Addresses |
| 44. Wildcard Matching | 94. Binary Tree Inorder Traversal |
| 45. Jump Game II | 95. Unique Binary Search Trees II |
| 46. Permutations | 96. Unique Binary Search Trees |
| 47. Permutations II | 97. Interleaving String |
| 48. Rotate Image | 98. Validate Binary Search Tree |
| 49. Group Anagrams | 99. Recover Binary Search Tree |
| 50. Pow(x, n) | 100. Same Tree |
| 101-150 | 151-200 |
| 101. Symmetric Tree | 151. Reverse Words in a String |
| 102. Binary Tree Level Order Traversal | 152. Maximum Product Subarray |
| 103. Binary Tree Zigzag Level Order Traversal | 153. Find Minimum in Rotated Sorted Array |
| 104. Maximum Depth of Binary Tree | 154. Find Minimum in Rotated Sorted Array II |
| 105. Construct Binary Tree from Preorder and Inorder Traversal | 155. Min Stack |
| 106. Construct Binary Tree from Inorder and Postorder Traversal |
156. |
| 107. Binary Tree Level Order Traversal II |
157. |
| 108. Convert Sorted Array to Binary Search Tree |
158. |
| 109. Convert Sorted List to Binary Search Tree |
159. |
| 110. Balanced Binary Tree | 160. Intersection of Two Linked Lists |
| 111. Minimum Depth of Binary Tree |
161. |
| 112. Path Sum | 162. Find Peak Element |
| 113. Path Sum II |
163. |
| 114. Flatten Binary Tree to Linked List | 164. Maximum Gap |
| 115. Distinct Subsequences | 165. Compare Version Numbers |
| 116. Populating Next Right Pointers in Each Node | 166. Fraction to Recurring Decimal |
| 117. Populating Next Right Pointers in Each Node II | 167. Two Sum II - Input Array Is Sorted |
| 118. Pascal's Triangle | 168. Excel Sheet Column Title |
| 119. Pascal's Triangle II | 169. Majority Element |
| 120. Triangle |
170. |
| 121. Best Time to Buy and Sell Stock | 171. Excel Sheet Column Number |
| 122. Best Time to Buy and Sell Stock | 172. Factorial Trailing Zeroes |
| 123. Best Time to Buy and Sell Stock III | 173. Binary Search Tree Iterator |
| 124. Binary Tree Maximum Path Sum | 174. Dungeon Game |
| 125. Valid Palindrome | 175. Combine Two Tables |
| 126. Word Ladder II | 176. Second Highest Salary |
| 127. Word Ladder | 177. Nth Highest Salary |
| 128. Longest Consecutive Sequence | 178. Rank Scores |
| 129. Sum Root to Leaf Numbers | 179. Largest Number |
| 130. Surrounded Regions | 180. Consecutive Numbers |
| 131. Palindrome Partitioning | 181. Employees Earning More Than Their Managers |
| 132. Palindrome Partitioning II | 182. Duplicate Emails |
| 133. Clone Graph | 183. Customers Who Never Order |
| 134. Gas Station | 184. Department Highest Salary |
| 135. Candy | 185. Department Top Three Salaries |
| 136. Single Number |
186. |
| 137. Single Number II | 187. Repeated DNA Sequences |
| 138. Copy List with Random Pointer | 188. Best Time to Buy and Sell Stock IV |
| 139. Word Break | 189. Rotate Array |
| 140. Word Break II | 190. Reverse Bits |
| 141. Linked List Cycle | 191. Number of 1 Bits |
| 142. Linked List Cycle II | 192. Word Frequency |
| 143. Reorder List | 193. Valid Phone Numbers |
| 144. Binary Tree Preorder Traversal | 194. Transpose File |
| 145. Binary Tree Postorder Traversal | 195. Tenth Line |
| 146. LRU Cache | 196. Delete Duplicate Emails |
| 147. Insertion Sort List | 197. Rising Temperature |
| 148. Sort List | 198. House Robber |
| 149. Max Points on a Line | 199. Binary Tree Right Side View |
| 150. Evaluate Reverse Polish Notation | 200. Number of Islands |
| 201-250 | 251-300 |
| 201. 201. Bitwise AND of Numbers Range |
251. |
| 202. Happy Number |
252. |
| 203. Remove Linked List Elements |
253. |
| 204. Count Primes |
254. |
| 205. Isomorphic Strings |
255. |
| 206. Reverse Linked List |
256. |
| 207. Course Schedule | 257. Binary Tree Paths |
| 208. Implement Trie (Prefix Tree) | 258. Add Digits |
| 209. Minimum Size Subarray Sum |
259. |
| 210. Course Schedule II | 260. Single Number III |
| 211. Design Add and Search Words Data Structure |
261. |
| 212. Word Search II | 262. Trips and Users |
| 213. House Robber II | 263. Ugly Number |
| 214. Shortest Palindrome | 264. Ugly Number II |
| 215. Kth Largest Element in an Array |
265. |
| 216. Combination Sum III |
266. |
| 217. Contains Duplicate |
267. |
| 218. The Skyline Problem | 268. Missing Number |
| 219. Contains Duplicate II |
269. |
| 220. Contains Duplicate III |
270. |
| 221. Maximal Square |
271. |
| 222. Count Complete Tree Nodes |
272. |
| 223. Rectangle Area | 273. Integer to English Words |
| 224. Basic Calculator | 274. H-Index |
| 225. Implement Stack using Queues | 275. H-Index II |
| 226. Invert Binary Tree |
276. |
| 227. Basic Calculator II |
277. |
| 228. Summary Ranges | 278. First Bad Version |
| 229. Majority Element II | 279. Perfect Squares |
| 230. Kth Smallest Element in a BST |
280. |
| 231. Power of Two |
281. |
| 232. Implement Queue using Stacks | 282. Expression Add Operators |
| 233. Number of Digit One | 283. Move Zeroes |
| 234. Palindrome Linked List | 284. Peeking Iterator |
| 235. Lowest Common Ancestor of a Binary Search Tree |
285. |
| 236. Lowest Common Ancestor of a Binary Tree |
286. |
| 237. Delete Node in a Linked List | 287. Find the Duplicate Number |
| 238. Product of Array Except Self |
288. |
| 239. Sliding Window Maximum | 289. Game of Life |
| 240. Search a 2D Matrix II | 290. Word Pattern |
| 241. Different Ways to Add Parentheses |
291. |
| 242. Valid Anagram | 292. Nim Game |
|
243. |
293. |
|
244. |
294. |
|
245. |
295. Find Median from Data Stream |
|
246. |
296. |
|
247. |
297. Serialize and Deserialize Binary Tree |
|
248. |
298. |
|
249. |
299. Bulls and Cows |
|
250. |
300. Longest Increasing Subsequence |
| 301-350 | 351-400 |
| 301. Remove Invalid Parentheses |
351. |
|
302. |
352. Data Stream as Disjoint Intervals |
| 303. Range Sum Query - Immutable |
353. |
| 304. Range Sum Query 2D - Immutable | 354. Russian Doll Envelopes |
|
305. |
355. |
| 306. Additive Number |
356. |
| 307. Range Sum Query - Mutable | 357. Count Numbers with Unique Digits |
|
308. |
358. |
| 309. Best Time to Buy and Sell Stock with Cooldown |
359. |
| 310. Minimum Height Trees |
360. |
|
311. |
361. |
| 312. Burst Balloons |
362. |
| 313. Super Ugly Number | 363. Max Sum of Rectangle No Larger Than K |
|
314. |
364. Nested List Weight Sum II |
| 315. Count of Smaller Numbers After Self | 365. Water and Jug Problem |
| 316. Remove Duplicate Letters |
366. |
|
317. |
367. Valid Perfect Square |
| 318. Maximum Product of Word Lengths | 368. Largest Divisible Subset |
| 319. Bulb Switcher |
369. |
|
320. |
370. |
| 321. Create Maximum Number | 371. Sum of Two Integers |
| 322. Coin Change | 372. Super Pow |
|
323. |
373. Find K Pairs with Smallest Sums |
| 324. Wiggle Sort II | 374. Guess Number Higher or Lower |
|
325. |
375. Guess Number Higher or Lower II |
| 326. Power of Three | 376. Wiggle Subsequence |
| 327. Count of Range Sum | 377. Combination Sum IV |
| 328. Odd Even Linked List | 378. Kth Smallest Element in a Sorted Matrix |
| 329. Longest Increasing Path in a Matrix |
379. |
| 330. Patching Array | 380. Insert Delete GetRandom O(1) |
| 331. Verify Preorder Serialization of a Binary Tree | 381. Insert Delete GetRandom O(1) - Duplicates allowed |
| 332. Reconstruct Itinerary | 382. Linked List Random Node |
|
333. |
383. Ransom Note |
| 334. Increasing Triplet Subsequence | 384. Shuffle an Array |
| 335. Self Crossing | 385. Mini Parser |
| 336. Palindrome Pairs | 386. Lexicographical Numbers |
| 337. House Robber III | 387. First Unique Character in a String |
| 338. Counting Bits | 388. Longest Absolute File Path |
|
339. |
389. Find the Difference |
|
340. |
390. Elimination Game |
| 341. Flatten Nested List Iterator | 391. Perfect Rectangle |
| 342. Power of Four | 392. Is Subsequence |
| 343. Integer Break | 393. UTF-8 Validation |
| 344. Reverse String | 394. Decode String |
| 345. Reverse Vowels of a String | 395. Longest Substring with At Least K Repeating Characters |
|
346. |
396. Rotate Function |
| 347. Top K Frequent Elements | 397. Integer Replacement |
|
348. |
398. Random Pick Index |
| 349. Intersection of Two Arrays | 399. Evaluate Division |
| 350. Intersection of Two Arrays II | 400. Nth Digit |
| 401-450 | 451-500 |
| 401. Binary Watch | 451. Sort Characters By Frequency |
| 402. Remove K Digits | 452. Minimum Number of Arrows to Burst Balloons |
| 403. Frog Jump | 453. Minimum Moves to Equal Array Elements |
| 404. Sum of Left Leaves | 454. Four Sum II |
| 405. Convert a Number to Hexadecimal | 455. Assign Cookies |
| 406. Queue Reconstruction by Height | 456. 132 Pattern |
| 407. Trapping Rain Water II | 457. Circular Array Loop |
|
408. |
458. Poor Pigs |
| 409. Longest Palindrome | 459. Repeated Substring Pattern |
| 410. Split Array Largest Sum | 460. LFU Cache |
|
411. |
461. Hamming Distance |
| 412. Fizz Buzz | 462. Minimum Moves to Equal Array Elements II |
| 413. Arithmetic Slices | 463. Island Perimeter |
| 414. Third Maximum Number | 464. Can I Win |
| 415. Add Strings |
465. |
| 416. Partition Equal Subset Sum | 466. Count The Repetitions |
| 417. Pacific Atlantic Water Flow | 467. Unique Substrings in Wraparound String |
|
418. |
468. Validate IP Address |
| 419. Battleships in a Board |
469. |
| 420. Strong Password Checker | 470. Implement Rand10() Using Rand7() |
| 421. Maximum XOR of Two Numbers in an Array |
471. |
|
422. |
472. Concatenated Words |
| 423. Reconstruct Original Digits from English | 473. Matchsticks to Square |
| 424. Longest Repeating Character Replacement | 474. Ones and Zeroes |
|
425. |
475. Heaters |
|
426. |
476. Number Complement |
| 427. Construct Quad Tree | 477. Total Hamming Distance |
|
428. |
478. Generate Random Point in a Circle |
| 429. N-ary Tree Level Order Traversal | 479. Largest Palindrome Product |
| 430. Flatten a Multilevel Doubly Linked List | 480. Sliding Window Median |
|
431. |
481. Magical String |
| 432. All O'one Data Structure | 482. License Key Formatting |
| 433. Minimum Genetic Mutation | 483. Smallest Good Base |
| 434. Number of Segments in a String |
484. |
| 435. Non-overlapping Intervals | 485. Max Consecutive Ones |
| 436. Find Right Interval | 486. Predict the Winner |
| 437. Path Sum III |
487. |
| 438. Find All Anagrams in a String | 488. Zuma Game |
|
439. |
489. |
| 440. K-th Smallest in Lexicographical Order |
490. |
| 441. Arranging Coins | 491. Non-decreasing Subsequences |
| 442. Find All Duplicates in an Array | 492. Construct the Rectangle |
| 443. String Compression | 493. Reverse Pairs |
|
444. |
494. Target Sum |
| 445. Add Two Numbers II | 495. Teemo Attacking |
| 446. Arithmetic Slices II - Subsequence | 496. Next Greater Element I |
| 447. Number of Boomerangs | 497. Random Point in Non-overlapping Rectangles |
| 448. Find All Numbers Disappeared in an Array | 498. Diagonal Traverse |
| 449. Serialize and Deserialize BST |
499. |
| 450. Delete Node in a BST | 500. Keyboard Row |