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:

  1. The link to LeetCode, so you can read the statement and submit your answer.
  2. The pattern: the name of the technique that solves the problem.
  3. The template to memorize: the short code shape behind the solution. The link opens the template.
  4. The idea: the key insight in one to three sentences, with the time and the space complexity.
  5. 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 vet and go 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

StageCategoryProblemsTemplates to memorize
1Arrays and Hashing9A: Seen set; B: Count array or count map; C: Bucket by count; D: Prefix and suffix passes; E: Length prefix
2Two Pointers5A: Converging pointers; B: Sort, fix one, converge; C: Two pointers with a running maximum
3Sliding Window6A: Best so far in one pass; B: Variable window, longest; C: Fixed window; D: Shortest window with a need counter; E: Monotonic deque
4Stack7A: Matching stack; B: Paired stack; C: Stack as evaluator; D: Backtracking with counters; E: Monotonic stack
5Binary Search7A: Exact value; B: First true; C: Rotated sorted slice; D: Partition of two sorted slices
6Linked List11A: 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
7Trees15A: 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
8Tries3A: Trie node, insert and walk; B: DFS on the trie for wildcards; C: Trie plus grid backtracking
9Heap and Priority Queue7A: 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
10Backtracking9A: 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
11Graphs13A: 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
12Advanced Graphs6A: 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
131-D Dynamic Programming12A: 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
142-D Dynamic Programming11A: 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
15Greedy8A: 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
16Intervals6A: 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
17Math and Geometry8A: 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
18Bit Manipulation7A: 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

#ProblemLevelPatternTemplateGo
1217. Contains DuplicateEasyHash setA: Seen setsolution
2242. Valid AnagramEasyLetter countB: Count array or count mapsolution
31. Two SumEasyHash map of value to indexA: Seen setsolution
449. Group AnagramsMediumHash map with a count keyB: Count array or count mapsolution
5347. Top K Frequent ElementsMediumCount map, then bucket sortC: Bucket by countsolution
6271. Encode and Decode Strings (free)MediumLength-prefix encodingE: Length prefixsolution
7238. Product of Array Except SelfMediumPrefix and suffix productsD: Prefix and suffix passessolution
836. Valid SudokuMediumSeen sets for rows, columns and boxesA: Seen setsolution
9128. Longest Consecutive SequenceMediumHash set, count from the start of each runA: Seen setsolution

Stage 2: Two Pointers

Stage 3: Sliding Window

Stage 4: Stack

#ProblemLevelPatternTemplateGo
28704. Binary SearchEasyBinary search, exact valueA: Exact valuesolution
2974. Search a 2D MatrixMediumBinary search, exact valueA: Exact valuesolution
30875. Koko Eating BananasMediumBinary search on the answerB: First truesolution
31153. Find Minimum in Rotated Sorted ArrayMediumFirst true on a rotated sliceB: First truesolution
3233. Search in Rotated Sorted ArrayMediumBinary search on a rotated sliceC: Rotated sorted slicesolution
33981. Time Based Key-Value StoreMediumMap of sorted slices, first trueB: First truesolution
344. Median of Two Sorted ArraysHardBinary search on a partitionD: Partition of two sorted slicessolution

Stage 6: Linked List

Stage 7: Trees

#ProblemLevelPatternTemplateGo
46226. Invert Binary TreeEasyRecursive DFS, swap the childrenA: DFS that returns a valuesolution
47104. Maximum Depth of Binary TreeEasyRecursive DFS that returns the heightA: DFS that returns a valuesolution
48543. Diameter of Binary TreeEasyDFS returns the height, records the diameterB: DFS that returns one value and records anothersolution
49110. Balanced Binary TreeEasyDFS returns the height, records the balanceB: DFS that returns one value and records anothersolution
50100. Same TreeEasyRecursive DFS on two treesA: DFS that returns a valuesolution
51572. Subtree of Another TreeEasyDFS with a same-tree testA: DFS that returns a valuesolution
52235. Lowest Common Ancestor of a Binary Search TreeMediumBST walk to the split pointE: BST walk that uses the ordersolution
53102. Binary Tree Level Order TraversalMediumBFS by levelD: BFS by levelsolution
54199. Binary Tree Right Side ViewMediumBFS by level, keep the last nodeD: BFS by levelsolution
551448. Count Good Nodes in Binary TreeMediumDFS that passes the path maximum downC: DFS that passes state downsolution
5698. Validate Binary Search TreeMediumDFS that passes the limits downC: DFS that passes state downsolution
57230. Kth Smallest Element in a BSTMediumInorder walk of a BST with a stackE: BST walk that uses the ordersolution
58105. Construct Binary Tree from Preorder and Inorder TraversalMediumPreorder cursor plus inorder index mapF: Preorder build with a cursorsolution
59124. Binary Tree Maximum Path SumHardDFS returns one branch, records the full pathB: DFS that returns one value and records anothersolution
60297. Serialize and Deserialize Binary TreeHardPreorder DFS with null markersF: Preorder build with a cursorsolution

Stage 8: Tries

Stage 9: Heap and Priority Queue

Stage 10: Backtracking

Stage 11: Graphs

Stage 12: Advanced Graphs

Stage 13: 1-D Dynamic Programming

Stage 14: 2-D Dynamic Programming

Stage 15: Greedy

#ProblemLevelPatternTemplateGo
12253. Maximum SubarrayMediumKadane’s running sumA: Running sum with a resetsolution
12355. Jump GameMediumGreedy farthest reachB: Farthest reachsolution
12445. Jump Game IIMediumGreedy levels, as in BFSB: Farthest reachsolution
125134. Gas StationMediumGreedy running total with a resetA: Running sum with a resetsolution
126846. Hand of StraightsMediumSort, then take the smallest firstC: Sort, then take the smallest firstsolution
1271899. Merge Triplets to Form Target TripletMediumGreedy filter, then combineD: Filter, then combinesolution
128763. Partition LabelsMediumLast index, then extend the endE: Last index, then extend the endsolution
129678. Valid Parenthesis StringMediumGreedy range of open countsF: Range of possible countssolution

Stage 16: Intervals

Stage 17: Math and Geometry

#ProblemLevelPatternTemplateGo
13648. Rotate ImageMediumTranspose, then reverse the rowsA: Transpose, then reversesolution
13754. Spiral MatrixMediumFour boundaries that shrinkB: Four boundaries that shrinksolution
13873. Set Matrix ZeroesMediumFirst row and column as markersC: Markers in the first row and columnsolution
139202. Happy NumberEasyDigit loop with cycle detectionD: Digit loop with a carrysolution
14066. Plus OneEasyDigit loop with a carryD: Digit loop with a carrysolution
14150. Pow(x, n)MediumFast power by squaringE: Fast power by squaringsolution
14243. Multiply StringsMediumGrade-school multiplication with digitsD: Digit loop with a carrysolution
1432013. Detect SquaresMediumCount map of pointsF: Count map of pointssolution

Stage 18: Bit Manipulation

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

  1. Open the stage page. Read the templates and their signals.
  2. Write each template from memory in an empty file. Compile it. Compare it with the page.
  3. Solve the problems of the stage with the loop below.
  4. At the end of the stage, write each template one more time from memory.

The loop for each problem

  1. Open the LeetCode link. Read the problem. Name the pattern and the template before you write code.
  2. 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.
  3. 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.
  4. If you are blocked, open step 2, the idea. Open step 3, the code, only if the idea is not enough.
  5. Close the page. Type the solution from memory. Do not paste it.
  6. Say the idea aloud in two sentences. Then say the time and the space complexity.
  7. 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 problemPatternStage
Count, duplicate, group, find a pair in unsorted dataHash map or hash set1
Sorted input and a pair, or a palindromeTwo pointers2
Longest or shortest contiguous part with a conditionSliding window3
Brackets, or the next greater or smaller itemStack, monotonic stack4
Sorted input and O(log n), or “the minimum value that is enough”Binary search5
A linked list: reverse, merge, cycle, middleReverse, dummy head, fast and slow6
Tree depth, path, validity or levelsDFS, BFS by level7
Words with a shared prefix, or a search with wildcardsTrie8
The K largest, smallest or closest, or a median of a streamHeap9
All subsets, permutations, combinations or boardsBacktracking10
Islands, regions, connected groups, an order with dependenciesGrid DFS, BFS, topological sort, union-find11
Shortest path with weights, or the cheapest way to connect all nodesDijkstra, Bellman-Ford, Prim12
Count the ways, or the best value over choices, on one sequence1-D dynamic programming13
The same, on two strings, a grid, or an index and a second value2-D dynamic programming14
A local best choice that is always safeGreedy15
Intervals that overlap, meetings, roomsSort, then merge or sweep16
A matrix to change in place, digits, powersMath and geometry17
”With no extra memory”, single bits, XORBit manipulation18

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.

21 items under this folder.