Neetcode 250 (Java)
The NeetCode 250 problem set, grouped by the same categories as the NeetCode roadmap, each solved in Java with a brute force and an optimal solution.
Start with 217. Contains Duplicate →Arrays & Hashing
Frequency counting, grouping, and lookups with hash maps and sets.
- 1.217. Contains Duplicate
- 2.242. Valid Anagram
- 3.1. Two Sum
- 4.49. Group Anagrams
- 5.347. Top K Frequent Elements
- 6.271. Encode and Decode Strings
- 7.238. Product of Array Except Self
- 8.36. Valid Sudoku
- 9.122. Best Time to Buy and Sell Stock II
- 10.128. Longest Consecutive Sequence
- 11.1929. Concatenation of Array
- 12.14. Longest Common Prefix
- 13.27. Remove Element
- 14.169. Majority Element
- 15.304. Range Sum Query 2D - Immutable
- 16.75. Sort Colors
- 17.560. Subarray Sum Equals K
- 18.705. Design HashSet
- 19.706. Design HashMap
- 20.912. Sort an Array
- 21.229. Majority Element II
- 22.41. First Missing Positive
Two Pointers
Scan from both ends or with two indices instead of nested loops.
- 23.125. Valid Palindrome
- 24.167. Two Sum II - Input Array Is Sorted
- 25.15. 3Sum
- 26.11. Container With Most Water
- 27.42. Trapping Rain Water
- 28.1768. Merge Strings Alternately
- 29.344. Reverse String
- 30.88. Merge Sorted Array
- 31.26. Remove Duplicates from Sorted Array
- 32.680. Valid Palindrome II
- 33.18. 4Sum
- 34.189. Rotate Array
- 35.881. Boats to Save People
Sliding Window
Maintain a moving range over an array or string instead of recomputing it.
- 36.121. Best Time to Buy and Sell Stock
- 37.3. Longest Substring Without Repeating Characters
- 38.424. Longest Repeating Character Replacement
- 39.567. Permutation in String
- 40.76. Minimum Window Substring
- 41.239. Sliding Window Maximum
- 42.219. Contains Duplicate II
- 43.209. Minimum Size Subarray Sum
- 44.658. Find K Closest Elements
Stack
Last-in, first-out problems: matching pairs, monotonic stacks, and expression evaluation.
- 45.20. Valid Parentheses
- 46.155. Min Stack
- 47.150. Evaluate Reverse Polish Notation
- 48.22. Generate Parentheses
- 49.739. Daily Temperatures
- 50.853. Car Fleet
- 51.84. Largest Rectangle in Histogram
- 52.682. Baseball Game
- 53.225. Implement Stack using Queues
- 54.232. Implement Queue using Stacks
- 55.735. Asteroid Collision
- 56.901. Online Stock Span
- 57.71. Simplify Path
- 58.394. Decode String
- 59.895. Maximum Frequency Stack
Binary Search
Halve the search space on sorted data or on a monotonic answer.
- 60.704. Binary Search
- 61.74. Search a 2D Matrix
- 62.875. Koko Eating Bananas
- 63.153. Find Minimum in Rotated Sorted Array
- 64.33. Search in Rotated Sorted Array
- 65.981. Time Based Key-Value Store
- 66.4. Median of Two Sorted Arrays
- 67.35. Search Insert Position
- 68.374. Guess Number Higher or Lower
- 69.69. Sqrt(x)
- 70.1011. Capacity To Ship Packages Within D Days
- 71.81. Search in Rotated Sorted Array II
- 72.410. Split Array Largest Sum
- 73.1095. Find in Mountain Array
Linked List
Pointer manipulation, fast and slow pointers, and designs built on linked lists.
- 74.206. Reverse Linked List
- 75.21. Merge Two Sorted Linked Lists
- 76.141. Linked List Cycle Detection
- 77.143. Reorder List
- 78.19. Remove Node From End of Linked List
- 79.138. Copy List With Random Pointer
- 80.2. Add Two Numbers
- 81.287. Find the Duplicate Number
- 82.146. LRU Cache
- 83.23. Merge K Sorted Linked Lists
- 84.25. Reverse Nodes In K-Group
- 85.92. Reverse Linked List II
- 86.622. Design Circular Queue
- 87.460. LFU Cache
Trees
Binary tree recursion, traversals, and binary search trees.
- 88.226. Invert Binary Tree
- 89.104. Maximum Depth of Binary Tree
- 90.543. Diameter of Binary Tree
- 91.110. Balanced Binary Tree
- 92.100. Same Binary Tree
- 93.572. Subtree of Another Binary Tree
- 94.235. Lowest Common Ancestor in Binary Search Tree
- 95.102. Binary Tree Level Order Traversal
- 96.199. Binary Tree Right Side View
- 97.1448. Count Good Nodes in Binary Tree
- 98.98. Validate Binary Search Tree
- 99.230. Kth Smallest Integer in BST
- 100.105. Construct Binary Tree From Preorder and Inorder Traversal
- 101.124. Binary Tree Maximum Path Sum
- 102.297. Serialize and Deserialize Binary Tree
- 103.94. Binary Tree Inorder Traversal
- 104.144. Binary Tree Preorder Traversal
- 105.145. Binary Tree Postorder Traversal
- 106.701. Insert into a Binary Search Tree
- 107.450. Delete Node in a BST
- 108.427. Construct Quad Tree
- 109.337. House Robber III
- 110.1325. Delete Leaves With a Given Value
Tries
Prefix trees for fast prefix lookup, wildcard search, and searching many words at once.
Heap / Priority Queue
Repeatedly pull out the smallest or largest item, or keep only the top k.
- 115.703. Kth Largest Element in a Stream
- 116.1046. Last Stone Weight
- 117.973. K Closest Points to Origin
- 118.215. Kth Largest Element in an Array
- 119.621. Task Scheduler
- 120.355. Design Twitter
- 121.295. Find Median From Data Stream
- 122.767. Reorganize String
- 123.1834. Single-Threaded CPU
- 124.1405. Longest Happy String
- 125.1094. Car Pooling
- 126.502. IPO
Backtracking
Explore choices depth first, undo them, and prune dead ends.
- 127.78. Subsets
- 128.39. Combination Sum
- 129.40. Combination Sum II
- 130.46. Permutations
- 131.90. Subsets II
- 132.79. Word Search
- 133.131. Palindrome Partitioning
- 134.17. Letter Combinations of a Phone Number
- 135.51. N-Queens
- 136.1863. Sum of All Subset XOR Totals
- 137.77. Combinations
- 138.47. Permutations II
- 139.698. Partition to K Equal Sum Subsets
- 140.473. Matchsticks to Square
- 141.52. N-Queens II
- 142.140. Word Break II
Graphs
Grid and graph traversal with DFS, BFS, topological sort, and union-find.
- 143.200. Number of Islands
- 144.133. Clone Graph
- 145.695. Max Area of Island
- 146.417. Pacific Atlantic Water Flow
- 147.130. Surrounded Regions
- 148.994. Rotting Oranges
- 149.286. Walls and Gates
- 150.207. Course Schedule
- 151.210. Course Schedule II
- 152.684. Redundant Connection
- 153.323. Number of Connected Components in an Undirected Graph
- 154.261. Graph Valid Tree
- 155.127. Word Ladder
- 156.463. Island Perimeter
- 157.953. Verifying an Alien Dictionary
- 158.997. Find the Town Judge
- 159.752. Open the Lock
- 160.1462. Course Schedule IV
- 161.721. Accounts Merge
- 162.399. Evaluate Division
- 163.310. Minimum Height Trees
Advanced Graphs
Shortest paths, minimum spanning trees, Eulerian paths, and topological ordering.
- 164.332. Reconstruct Itinerary
- 165.1584. Min Cost to Connect All Points
- 166.743. Network Delay Time
- 167.778. Swim in Rising Water
- 168.269. Alien Dictionary
- 169.787. Cheapest Flights Within K Stops
- 170.1631. Path With Minimum Effort
- 171.1489. Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree
- 172.2392. Build a Matrix With Conditions
- 173.2709. Greatest Common Divisor Traversal
1-D Dynamic Programming
Break a problem into overlapping subproblems indexed by one variable.
- 174.70. Climbing Stairs
- 175.746. Min Cost Climbing Stairs
- 176.198. House Robber
- 177.213. House Robber II
- 178.5. Longest Palindromic Substring
- 179.647. Palindromic Substrings
- 180.91. Decode Ways
- 181.322. Coin Change
- 182.152. Maximum Product Subarray
- 183.139. Word Break
- 184.300. Longest Increasing Subsequence
- 185.416. Partition Equal Subset Sum
- 186.1137. N-th Tribonacci Number
- 187.279. Perfect Squares
- 188.377. Combination Sum IV
- 189.343. Integer Break
- 190.1406. Stone Game III
2-D Dynamic Programming
Grid, string-pair, and interval DP with two changing indices.
- 191.62. Unique Paths
- 192.1143. Longest Common Subsequence
- 193.309. Best Time to Buy and Sell Stock with Cooldown
- 194.518. Coin Change II
- 195.494. Target Sum
- 196.97. Interleaving String
- 197.329. Longest Increasing Path in a Matrix
- 198.115. Distinct Subsequences
- 199.72. Edit Distance
- 200.312. Burst Balloons
- 201.10. Regular Expression Matching
- 202.64. Minimum Path Sum
- 203.63. Unique Paths II
- 204.877. Stone Game
- 205.1049. Last Stone Weight II
- 206.1140. Stone Game II
Greedy
Make the locally best choice at each step and prove it is safe.
- 207.53. Maximum Subarray
- 208.55. Jump Game
- 209.45. Jump Game II
- 210.134. Gas Station
- 211.846. Hand of Straights
- 212.1899. Merge Triplets to Form Target Triplet
- 213.763. Partition Labels
- 214.678. Valid Parenthesis String
- 215.860. Lemonade Change
- 216.918. Maximum Sum Circular Subarray
- 217.978. Longest Turbulent Subarray
- 218.1871. Jump Game VII
- 219.649. Dota2 Senate
- 220.135. Candy
Intervals
Sort by start or end and sweep to merge, insert, or count overlaps.
Math & Geometry
Matrix transformations, number manipulation, and coordinate tricks.
- 228.48. Rotate Image
- 229.54. Spiral Matrix
- 230.73. Set Matrix Zeroes
- 231.202. Happy Number
- 232.66. Plus One
- 233.50. Pow(x, n)
- 234.43. Multiply Strings
- 235.2013. Detect Squares
- 236.13. Roman to Integer
- 237.168. Excel Sheet Column Title
- 238.1071. Greatest Common Divisor of Strings
- 239.2807. Insert Greatest Common Divisors in Linked List
- 240.867. Transpose Matrix
Bit Manipulation
XOR tricks, shifts, and masks on integers.
