CircleCI Codecov OpenJDK Python Node

Let's grind LeetCode!

The project logo.

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

Visit problem set

Neetcode 150

Visit problem set

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. Binary Tree Upside Down
107. Binary Tree Level Order Traversal II 157. Read N Characters Given Read4
108. Convert Sorted Array to Binary Search Tree 158. Read N Characters Given Read4 II
109. Convert Sorted List to Binary Search Tree 159. Longest Substring with At Most Two Distinct Characters
110. Balanced Binary Tree 160. Intersection of Two Linked Lists
111. Minimum Depth of Binary Tree 161. One Edit Distance
112. Path Sum 162. Find Peak Element
113. Path Sum II 163. Missing Ranges
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. Two Sum III - Data structure design
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. Reverse Words in a String II
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. Flatten 2D Vector
202. Happy Number 252. Meeting Rooms
203. Remove Linked List Elements 253. Meeting Rooms II
204. Count Primes 254. Factor Combinations
205. Isomorphic Strings 255. Verify Preorder Sequence in Binary Search Tree
206. Reverse Linked List 256. Paint House
207. Course Schedule 257. Binary Tree Paths
208. Implement Trie (Prefix Tree) 258. Add Digits
209. Minimum Size Subarray Sum 259. Three Sum Smaller
210. Course Schedule II 260. Single Number III
211. Design Add and Search Words Data Structure 261. Graph Valid Tree
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. Paint House II
216. Combination Sum III 266. Palindrome Permutation
217. Contains Duplicate 267. Palindrome Permutation II
218. The Skyline Problem 268. Missing Number
219. Contains Duplicate II 269. Alien Dictionary
220. Contains Duplicate III 270. Closest Binary Search Tree Value
221. Maximal Square 271. Encode and Decode Strings
222. Count Complete Tree Nodes 272. Closest Binary Search Tree Value II
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. Paint Fence
227. Basic Calculator II 277. Find the Celebrity
228. Summary Ranges 278. First Bad Version
229. Majority Element II 279. Perfect Squares
230. Kth Smallest Element in a BST 280. Wiggle Sort
231. Power of Two 281. Zigzag Iterator
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. Inorder Successor in BST
236. Lowest Common Ancestor of a Binary Tree 286. Walls and Gates
237. Delete Node in a Linked List 287. Find the Duplicate Number
238. Product of Array Except Self 288. Unique Word Abbreviation
239. Sliding Window Maximum 289. Game of Life
240. Search a 2D Matrix II 290. Word Pattern
241. Different Ways to Add Parentheses 291. Word Pattern II
242. Valid Anagram 292. Nim Game
243. Shortest Word Distance 293. Flip Game
244. Shortest Word Distance II 294. Flip Game II
245. Shortest Word Distance III 295. Find Median from Data Stream
246. Strobogrammatic Number 296. Best Meeting Point
247. Strobogrammatic Number II 297. Serialize and Deserialize Binary Tree
248. Strobogrammatic Number III 298. Binary Tree Longest Consecutive Sequence
249. Group Shifted Strings 299. Bulls and Cows
250. Count Univalue Subtrees 300. Longest Increasing Subsequence
301-350 351-400
301. Remove Invalid Parentheses 351. Android Unlock Patterns
302. Smallest Rectangle Enclosing Black Pixels 352. Data Stream as Disjoint Intervals
303. Range Sum Query - Immutable 353. Design Snake Game
304. Range Sum Query 2D - Immutable 354. Russian Doll Envelopes
305. Number of Islands II 355. Design Twitter
306. Additive Number 356. Line Reflection
307. Range Sum Query - Mutable 357. Count Numbers with Unique Digits
308. Range Sum Query 2D - Mutable 358. Rearrange String k Distance Apart
309. Best Time to Buy and Sell Stock with Cooldown 359. Logger Rate Limiter
310. Minimum Height Trees 360. Sort Transformed Array
311. Sparse Matrix Multiplication 361. Bomb Enemy
312. Burst Balloons 362. Design Hit Counter
313. Super Ugly Number 363. Max Sum of Rectangle No Larger Than K
314. Binary Tree Vertical Order Traversal 364. Nested List Weight Sum II
315. Count of Smaller Numbers After Self 365. Water and Jug Problem
316. Remove Duplicate Letters 366. Find Leaves of Binary Tree
317. Shortest Distance from All Buildings 367. Valid Perfect Square
318. Maximum Product of Word Lengths 368. Largest Divisible Subset
319. Bulb Switcher 369. Plus One Linked List
320. Generalized Abbreviation 370. Range Addition
321. Create Maximum Number 371. Sum of Two Integers
322. Coin Change 372. Super Pow
323. Number of Connected Components in an Undirected Graph 373. Find K Pairs with Smallest Sums
324. Wiggle Sort II 374. Guess Number Higher or Lower
325. Maximum Size Subarray Sum Equals k 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. Design Phone Directory
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. Largest BST Subtree 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. Nested List Weight Sum 389. Find the Difference
340. Longest Substring with At Most k Distinct Characters 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. Moving Average from Data Stream 396. Rotate Function
347. Top K Frequent Elements 397. Integer Replacement
348. Design Tic-Tac-Toe 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. Valid Word Abbreviation 458. Poor Pigs
409. Longest Palindrome 459. Repeated Substring Pattern
410. Split Array Largest Sum 460. LFU Cache
411. Minimum Unique Word Abbreviation 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. Optimal Account Balancing
416. Partition Equal Subset Sum 466. Count The Repetitions
417. Pacific Atlantic Water Flow 467. Unique Substrings in Wraparound String
418. Sentence Screen Fitting 468. Validate IP Address
419. Battleships in a Board 469. Convex Polygon
420. Strong Password Checker 470. Implement Rand10() Using Rand7()
421. Maximum XOR of Two Numbers in an Array 471. Encode String with Shortest Length
422. Valid Word Square 472. Concatenated Words
423. Reconstruct Original Digits from English 473. Matchsticks to Square
424. Longest Repeating Character Replacement 474. Ones and Zeroes
425. Word Squares 475. Heaters
426. Convert Binary Search Tree to Sorted Doubly Linked List 476. Number Complement
427. Construct Quad Tree 477. Total Hamming Distance
428. Serialize and Deserialize N-ary Tree 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. Encode N-ary Tree to Binary Tree 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. Find Permutation
435. Non-overlapping Intervals 485. Max Consecutive Ones
436. Find Right Interval 486. Predict the Winner
437. Path Sum III 487. Max Consecutive Ones II
438. Find All Anagrams in a String 488. Zuma Game
439. Ternary Expression Parser 489. Robot Room Cleaner
440. K-th Smallest in Lexicographical Order 490. The Maze
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. Sequence Reconstruction 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. The Maze III
450. Delete Node in a BST 500. Keyboard Row