NeetCode 150 in Go: a learning path
This path solves the 150 problems of the NeetCode 150 list in Go. It follows the same idea as Learn Go with LeetCode. You memorize a small number of templates, and each problem is one more use of a template.
Each problem has the same five parts. On a stage page, parts 2 to 5 are closed until you open them, so each page works as a test:
- The link to LeetCode, so you can read the statement and submit your answer.
- The pattern: the name of the technique that solves the problem.
- The template to memorize: the short code shape behind the solution. The link opens the template.
- The idea: the key insight in one to three sentences, with the time and the space complexity.
- The Go solution with comments. The comments explain the idea and the Go. They name the moves of the template in capitals, for example GROW, SHRINK, RECORD.
The code runs
All 150 solutions and all the templates were compiled and tested on 2026-11-11 with Go 1.24.7 (
gofmt,go vetandgo test). The tests use the examples from each problem statement and edge cases. The harder problems also have a comparison with a brute-force answer on random inputs. Each solution has the function name and the signature that LeetCode gives for Go, so you can paste it there.
If you are new to Go
Start with Learn Go with LeetCode. It teaches the Go syntax stage by stage, with about 60 of these problems. Then use this path for the full list. Each stage page links to the Go syntax that it needs.
The path on one page
| Stage | Category | Problems | Templates to memorize |
|---|---|---|---|
| 1 | Arrays and Hashing | 9 | A: Seen set; B: Count array or count map; C: Bucket by count; D: Prefix and suffix passes; E: Length prefix |
| 2 | Two Pointers | 5 | A: Converging pointers; B: Sort, fix one, converge; C: Two pointers with a running maximum |
| 3 | Sliding Window | 6 | A: Best so far in one pass; B: Variable window, longest; C: Fixed window; D: Shortest window with a need counter; E: Monotonic deque |
| 4 | Stack | 7 | A: Matching stack; B: Paired stack; C: Stack as evaluator; D: Backtracking with counters; E: Monotonic stack |
| 5 | Binary Search | 7 | A: Exact value; B: First true; C: Rotated sorted slice; D: Partition of two sorted slices |
| 6 | Linked List | 11 | A: Reverse a list; B: Dummy head; C: Fast and slow pointers; D: Hash map plus doubly linked list; E: Heap of nodes; F: Map from old node to new node |
| 7 | Trees | 15 | A: DFS that returns a value; B: DFS that returns one value and records another; C: DFS that passes state down; D: BFS by level; E: BST walk that uses the order; F: Preorder build with a cursor |
| 8 | Tries | 3 | A: Trie node, insert and walk; B: DFS on the trie for wildcards; C: Trie plus grid backtracking |
| 9 | Heap and Priority Queue | 7 | A: The five heap methods; B: Heap of size K; C: Max-heap by a different Less; D: Two heaps for the median; E: Max-heap plus cooldown queue; F: K-way merge with a heap |
| 10 | Backtracking | 9 | A: Choose, explore, undo with a start index; B: Skip duplicates after a sort; C: Permutations with a used slice; D: Grid path with mark and unmark; E: Cut a string into parts; F: One choice for each position, with sets |
| 11 | Graphs | 13 | A: Grid DFS (flood fill); B: BFS by level from many sources; C: Clone with a map; D: Topological sort; E: Union-find; F: BFS on an implicit graph |
| 12 | Advanced Graphs | 6 | A: Dijkstra with a heap; B: Prim with a heap; C: Bellman-Ford with a round limit; D: Hierholzer’s algorithm; E: Topological sort from comparisons; F: Min-heap of items |
| 13 | 1-D Dynamic Programming | 12 | A: Two variables; B: Table over a prefix or an amount; C: Best that ends at i; D: 0/1 knapsack on a boolean row; E: Expand from the centre |
| 14 | 2-D Dynamic Programming | 11 | A: Grid paths; B: Two strings table; C: Knapsack count on one row; D: State machine by day; E: Interval DP; F: DFS with memo on a grid |
| 15 | Greedy | 8 | A: Running sum with a reset; B: Farthest reach; C: Sort, then take the smallest first; D: Filter, then combine; E: Last index, then extend the end; F: Range of possible counts |
| 16 | Intervals | 6 | A: Sort by start, then merge; B: Three-phase insert; C: Sort by end, then greedy keep; D: Sweep of sorted starts and ends; E: Offline queries with a sort and a min-heap |
| 17 | Math and Geometry | 8 | A: Transpose, then reverse; B: Four boundaries that shrink; C: Markers in the first row and column; D: Digit loop with a carry; E: Fast power by squaring; F: Count map of points |
| 18 | Bit Manipulation | 7 | A: XOR cancels pairs; B: Remove the lowest set bit; C: DP on bits; D: Shift in and shift out; E: Add with XOR and carry; F: Digit loop with an overflow check |
The path has 95 templates for 150 problems.
All 150 problems
The Go column opens the commented solution. The Template column opens the template to memorize.
Stage 1: Arrays and Hashing
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 1 | 217. Contains Duplicate | Easy | Hash set | A: Seen set | solution |
| 2 | 242. Valid Anagram | Easy | Letter count | B: Count array or count map | solution |
| 3 | 1. Two Sum | Easy | Hash map of value to index | A: Seen set | solution |
| 4 | 49. Group Anagrams | Medium | Hash map with a count key | B: Count array or count map | solution |
| 5 | 347. Top K Frequent Elements | Medium | Count map, then bucket sort | C: Bucket by count | solution |
| 6 | 271. Encode and Decode Strings (free) | Medium | Length-prefix encoding | E: Length prefix | solution |
| 7 | 238. Product of Array Except Self | Medium | Prefix and suffix products | D: Prefix and suffix passes | solution |
| 8 | 36. Valid Sudoku | Medium | Seen sets for rows, columns and boxes | A: Seen set | solution |
| 9 | 128. Longest Consecutive Sequence | Medium | Hash set, count from the start of each run | A: Seen set | solution |
Stage 2: Two Pointers
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 10 | 125. Valid Palindrome | Easy | Converging pointers | A: Converging pointers | solution |
| 11 | 167. Two Sum II - Input Array Is Sorted | Medium | Converging pointers | A: Converging pointers | solution |
| 12 | 15. 3Sum | Medium | Sort, then converging pointers | B: Sort, fix one, converge | solution |
| 13 | 11. Container With Most Water | Medium | Converging pointers | A: Converging pointers | solution |
| 14 | 42. Trapping Rain Water | Hard | Two pointers with running maximums | C: Two pointers with a running maximum | solution |
Stage 3: Sliding Window
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 15 | 121. Best Time to Buy and Sell Stock | Easy | Best so far, one pass | A: Best so far in one pass | solution |
| 16 | 3. Longest Substring Without Repeating Characters | Medium | Variable window, longest | B: Variable window, longest | solution |
| 17 | 424. Longest Repeating Character Replacement | Medium | Variable window, longest | B: Variable window, longest | solution |
| 18 | 567. Permutation in String | Medium | Fixed window with letter counts | C: Fixed window | solution |
| 19 | 76. Minimum Window Substring | Hard | Shortest window with a need counter | D: Shortest window with a need counter | solution |
| 20 | 239. Sliding Window Maximum | Hard | Monotonic deque | E: Monotonic deque | solution |
Stage 4: Stack
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 21 | 20. Valid Parentheses | Easy | Matching stack | A: Matching stack | solution |
| 22 | 155. Min Stack | Medium | Paired stack | B: Paired stack | solution |
| 23 | 150. Evaluate Reverse Polish Notation | Medium | Stack as evaluator | C: Stack as evaluator | solution |
| 24 | 22. Generate Parentheses | Medium | Backtracking with counters | D: Backtracking with counters | solution |
| 25 | 739. Daily Temperatures | Medium | Monotonic stack | E: Monotonic stack | solution |
| 26 | 853. Car Fleet | Medium | Sort, then monotonic stack | E: Monotonic stack | solution |
| 27 | 84. Largest Rectangle in Histogram | Hard | Monotonic stack | E: Monotonic stack | solution |
Stage 5: Binary Search
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 28 | 704. Binary Search | Easy | Binary search, exact value | A: Exact value | solution |
| 29 | 74. Search a 2D Matrix | Medium | Binary search, exact value | A: Exact value | solution |
| 30 | 875. Koko Eating Bananas | Medium | Binary search on the answer | B: First true | solution |
| 31 | 153. Find Minimum in Rotated Sorted Array | Medium | First true on a rotated slice | B: First true | solution |
| 32 | 33. Search in Rotated Sorted Array | Medium | Binary search on a rotated slice | C: Rotated sorted slice | solution |
| 33 | 981. Time Based Key-Value Store | Medium | Map of sorted slices, first true | B: First true | solution |
| 34 | 4. Median of Two Sorted Arrays | Hard | Binary search on a partition | D: Partition of two sorted slices | solution |
Stage 6: Linked List
Stage 7: Trees
Stage 8: Tries
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 61 | 208. Implement Trie (Prefix Tree) | Medium | Trie (prefix tree) | A: Trie node, insert and walk | solution |
| 62 | 211. Design Add and Search Words Data Structure | Medium | Trie with wildcard DFS | A: Trie node, insert and walk, B: DFS on the trie for wildcards | solution |
| 63 | 212. Word Search II | Hard | Trie plus grid backtracking | A: Trie node, insert and walk, C: Trie plus grid backtracking | solution |
Stage 9: Heap and Priority Queue
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 64 | 703. Kth Largest Element in a Stream | Easy | Min-heap of size K | A: The five heap methods, B: Heap of size K | solution |
| 65 | 1046. Last Stone Weight | Easy | Max-heap simulation | C: Max-heap by a different Less | solution |
| 66 | 973. K Closest Points to Origin | Medium | Max-heap of size K | B: Heap of size K, C: Max-heap by a different Less | solution |
| 67 | 215. Kth Largest Element in an Array | Medium | Min-heap of size K | A: The five heap methods, B: Heap of size K | solution |
| 68 | 621. Task Scheduler | Medium | Max-heap plus cooldown queue | C: Max-heap by a different Less, E: Max-heap plus cooldown queue | solution |
| 69 | 355. Design Twitter | Medium | K-way merge with a heap | F: K-way merge with a heap | solution |
| 70 | 295. Find Median from Data Stream | Hard | Two heaps | D: Two heaps for the median | solution |
Stage 10: Backtracking
Stage 11: Graphs
Stage 12: Advanced Graphs
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 93 | 332. Reconstruct Itinerary | Hard | Eulerian path (Hierholzer) | D: Hierholzer’s algorithm | solution |
| 94 | 1584. Min Cost to Connect All Points | Medium | Minimum spanning tree (Prim) | B: Prim with a heap, F: Min-heap of items | solution |
| 95 | 743. Network Delay Time | Medium | Dijkstra with a heap | A: Dijkstra with a heap, F: Min-heap of items | solution |
| 96 | 778. Swim in Rising Water | Hard | Dijkstra, minimise the maximum | A: Dijkstra with a heap, F: Min-heap of items | solution |
| 97 | 269. Alien Dictionary (free) | Hard | Topological sort from comparisons | E: Topological sort from comparisons | solution |
| 98 | 787. Cheapest Flights Within K Stops | Medium | Bellman-Ford with a round limit | C: Bellman-Ford with a round limit | solution |
Stage 13: 1-D Dynamic Programming
Stage 14: 2-D Dynamic Programming
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 111 | 62. Unique Paths | Medium | Grid paths, one row | A: Grid paths | solution |
| 112 | 1143. Longest Common Subsequence | Medium | Two strings table | B: Two strings table | solution |
| 113 | 309. Best Time to Buy and Sell Stock with Cooldown | Medium | State machine by day | D: State machine by day | solution |
| 114 | 518. Coin Change II | Medium | Unbounded knapsack, count | C: Knapsack count on one row | solution |
| 115 | 494. Target Sum | Medium | 0/1 knapsack count, subset sum | C: Knapsack count on one row | solution |
| 116 | 97. Interleaving String | Medium | Two strings table, yes or no | B: Two strings table | solution |
| 117 | 329. Longest Increasing Path in a Matrix | Hard | DFS with memo on a grid | F: DFS with memo on a grid | solution |
| 118 | 115. Distinct Subsequences | Hard | Two strings table, count | B: Two strings table | solution |
| 119 | 72. Edit Distance | Medium | Two strings table, minimum | B: Two strings table | solution |
| 120 | 312. Burst Balloons | Hard | Interval DP, last to burst | E: Interval DP | solution |
| 121 | 10. Regular Expression Matching | Hard | Two strings table, pattern match | B: Two strings table | solution |
Stage 15: Greedy
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 122 | 53. Maximum Subarray | Medium | Kadane’s running sum | A: Running sum with a reset | solution |
| 123 | 55. Jump Game | Medium | Greedy farthest reach | B: Farthest reach | solution |
| 124 | 45. Jump Game II | Medium | Greedy levels, as in BFS | B: Farthest reach | solution |
| 125 | 134. Gas Station | Medium | Greedy running total with a reset | A: Running sum with a reset | solution |
| 126 | 846. Hand of Straights | Medium | Sort, then take the smallest first | C: Sort, then take the smallest first | solution |
| 127 | 1899. Merge Triplets to Form Target Triplet | Medium | Greedy filter, then combine | D: Filter, then combine | solution |
| 128 | 763. Partition Labels | Medium | Last index, then extend the end | E: Last index, then extend the end | solution |
| 129 | 678. Valid Parenthesis String | Medium | Greedy range of open counts | F: Range of possible counts | solution |
Stage 16: Intervals
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 130 | 57. Insert Interval | Medium | Three-phase insert | B: Three-phase insert | solution |
| 131 | 56. Merge Intervals | Medium | Sort by start, then merge | A: Sort by start, then merge | solution |
| 132 | 435. Non-overlapping Intervals | Medium | Sort by end, greedy keep | C: Sort by end, then greedy keep | solution |
| 133 | 252. Meeting Rooms (free) | Easy | Sort by start, compare neighbors | A: Sort by start, then merge | solution |
| 134 | 253. Meeting Rooms II (free) | Medium | Sweep of sorted starts and ends | D: Sweep of sorted starts and ends | solution |
| 135 | 1851. Minimum Interval to Include Each Query | Hard | Offline queries, sort plus min-heap | E: Offline queries with a sort and a min-heap | solution |
Stage 17: Math and Geometry
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 136 | 48. Rotate Image | Medium | Transpose, then reverse the rows | A: Transpose, then reverse | solution |
| 137 | 54. Spiral Matrix | Medium | Four boundaries that shrink | B: Four boundaries that shrink | solution |
| 138 | 73. Set Matrix Zeroes | Medium | First row and column as markers | C: Markers in the first row and column | solution |
| 139 | 202. Happy Number | Easy | Digit loop with cycle detection | D: Digit loop with a carry | solution |
| 140 | 66. Plus One | Easy | Digit loop with a carry | D: Digit loop with a carry | solution |
| 141 | 50. Pow(x, n) | Medium | Fast power by squaring | E: Fast power by squaring | solution |
| 142 | 43. Multiply Strings | Medium | Grade-school multiplication with digits | D: Digit loop with a carry | solution |
| 143 | 2013. Detect Squares | Medium | Count map of points | F: Count map of points | solution |
Stage 18: Bit Manipulation
| # | Problem | Level | Pattern | Template | Go |
|---|---|---|---|---|---|
| 144 | 136. Single Number | Easy | XOR cancels pairs | A: XOR cancels pairs | solution |
| 145 | 191. Number of 1 Bits | Easy | Remove the lowest set bit | B: Remove the lowest set bit | solution |
| 146 | 338. Counting Bits | Easy | DP on bits | C: DP on bits | solution |
| 147 | 190. Reverse Bits | Easy | Shift in and shift out | D: Shift in and shift out | solution |
| 148 | 268. Missing Number | Easy | XOR of indexes and values | A: XOR cancels pairs | solution |
| 149 | 371. Sum of Two Integers | Medium | Add with XOR and carry | E: Add with XOR and carry | solution |
| 150 | 7. Reverse Integer | Medium | Digit loop with an overflow check | F: Digit loop with an overflow check | solution |
How to use this path
The method and the tracker
LeetCode study method has the full method: the seven rules, the daily hour, the repeat schedule and the mistake list. LeetCode repeat tracker has one row for each problem, for the dates of your four sessions. LeetCode pattern drill shows you a problem and asks for its pattern.
The order
Follow the stages in order. Stage 1 to stage 7 are the base: each later stage uses them. In a stage, solve the problems in the order of the table. This order goes from the direct use of a template to the problems that combine two templates.
One new problem for each day needs about one hour, with the repeats. Two new problems for each day need about two hours. That speed completes the list in about 11 weeks, with one day each week for the repeats and the templates.
The loop for each stage
- Open the stage page. Read the templates and their signals.
- Write each template from memory in an empty file. Compile it. Compare it with the page.
- Solve the problems of the stage with the loop below.
- At the end of the stage, write each template one more time from memory.
The loop for each problem
- Open the LeetCode link. Read the problem. Name the pattern and the template before you write code.
- Open step 1 of the problem on the stage page, and compare your guess. A wrong guess is useful: read the signal of the correct template again.
- Set a timer for 20 minutes for an easy or medium problem, and 35 minutes for a hard problem. Write the solution in Go, in your editor.
- If you are blocked, open step 2, the idea. Open step 3, the code, only if the idea is not enough.
- Close the page. Type the solution from memory. Do not paste it.
- Say the idea aloud in two sentences. Then say the time and the space complexity.
- Write the solution again after 1 day, 3 days and 7 days.
Step 5 is the most important one. To read a solution feels like progress, but only recall builds memory.
The premium problems
Seven problems are premium on LeetCode: 271, 286, 323, 261, 269, 252 and 253. Each of them has a free link that opens the same problem on NeetCode. The solutions on this path use the LeetCode signature for Go.
Signals: which stage to open
Read the problem and look for these words first.
| Signal in the problem | Pattern | Stage |
|---|---|---|
| Count, duplicate, group, find a pair in unsorted data | Hash map or hash set | 1 |
| Sorted input and a pair, or a palindrome | Two pointers | 2 |
| Longest or shortest contiguous part with a condition | Sliding window | 3 |
| Brackets, or the next greater or smaller item | Stack, monotonic stack | 4 |
| Sorted input and O(log n), or “the minimum value that is enough” | Binary search | 5 |
| A linked list: reverse, merge, cycle, middle | Reverse, dummy head, fast and slow | 6 |
| Tree depth, path, validity or levels | DFS, BFS by level | 7 |
| Words with a shared prefix, or a search with wildcards | Trie | 8 |
| The K largest, smallest or closest, or a median of a stream | Heap | 9 |
| All subsets, permutations, combinations or boards | Backtracking | 10 |
| Islands, regions, connected groups, an order with dependencies | Grid DFS, BFS, topological sort, union-find | 11 |
| Shortest path with weights, or the cheapest way to connect all nodes | Dijkstra, Bellman-Ford, Prim | 12 |
| Count the ways, or the best value over choices, on one sequence | 1-D dynamic programming | 13 |
| The same, on two strings, a grid, or an index and a second value | 2-D dynamic programming | 14 |
| A local best choice that is always safe | Greedy | 15 |
| Intervals that overlap, meetings, rooms | Sort, then merge or sweep | 16 |
| A matrix to change in place, digits, powers | Math and geometry | 17 |
| ”With no extra memory”, single bits, XOR | Bit manipulation | 18 |
Progress
Mark a stage when you can do the three things in the list below it.
- Stage 1: Arrays and Hashing (9)
- Stage 2: Two Pointers (5)
- Stage 3: Sliding Window (6)
- Stage 4: Stack (7)
- Stage 5: Binary Search (7)
- Stage 6: Linked List (11)
- Stage 7: Trees (15)
- Stage 8: Tries (3)
- Stage 9: Heap and Priority Queue (7)
- Stage 10: Backtracking (9)
- Stage 11: Graphs (13)
- Stage 12: Advanced Graphs (6)
- Stage 13: 1-D Dynamic Programming (12)
- Stage 14: 2-D Dynamic Programming (11)
- Stage 15: Greedy (8)
- Stage 16: Intervals (6)
- Stage 17: Math and Geometry (8)
- Stage 18: Bit Manipulation (7)
A stage is complete when these three things are true:
- You can write each template of the stage from memory in less than five minutes, and it compiles.
- You solved each problem of the stage in Go, and the hard ones a second time.
- You can say the signal, the moves and the complexity of each template aloud.
Related
- LeetCode study method: how to practice so that the problems stay in memory.
- LeetCode repeat tracker: one row for each problem, with the dates of the four sessions.
- LeetCode pattern drill: read a problem, name the pattern, see the signal.
- Learn Go with LeetCode: a learning path: the Go syntax for each pattern, in 12 stages.
- Go LeetCode Snippets & Templates: short pieces of code to copy.
- LeetCode Patterns: the pattern notes and the progress tracker.
- Data Structures & Algorithms: the theory behind each structure.
- Go Programming: the Go area of the notebook.