Backtracking — NeetCode 250

This is a fresh, pattern-first study track for 15 core Backtracking problems. Read the foundation once, then work the problems in order. The aim is to recognize the decision tree before writing code.

Start here

  1. 00 - Backtracking Foundations
  2. 01 - Subsets and Duplicates
  3. 02 - Combinations and Targets
  4. 03 - Permutations
  5. 04 - Strings and Grids
  6. 05 - Constraint Search

The 15-problem track

#ProblemMain patternNote
1Sum of All Subsets XOR TotalInclude / exclude with an accumulator01 - Subsets and Duplicates
2SubsetsEnumerate every subset01 - Subsets and Duplicates
3Subsets IISubsets with duplicates01 - Subsets and Duplicates
4Combination SumTarget; reuse allowed02 - Combinations and Targets
5Combination Sum IITarget; use once; deduplicate02 - Combinations and Targets
6CombinationsChoose k increasing values02 - Combinations and Targets
7PermutationsArrange unused values03 - Permutations
8Permutations IIArrange values with frequencies03 - Permutations
9Generate ParenthesesBuild a valid constrained sequence04 - Strings and Grids
10Letter Combinations of a Phone NumberOne choice per position04 - Strings and Grids
11Palindrome PartitioningChoose the next valid cut04 - Strings and Grids
12Word SearchGrid DFS; path-local visited state04 - Strings and Grids
13N-QueensPlace under constraints05 - Constraint Search
14N-Queens IICount constrained placements05 - Constraint Search
15Matchsticks to SquareAssign items to equal buckets05 - Constraint Search

How to use each problem note

Before looking at the solution, answer these five prompts aloud:

  1. What does one DFS call mean?
  2. What is the next decision?
  3. Which state is shared and must be undone?
  4. When is a partial path impossible?
  5. What condition means the answer is complete?

Then write the recurrence from memory. If you get stuck, compare the problem with its nearest neighbor in the same note—not with a memorized full solution.

One-page pattern map

If the prompt says…Reach for…
“every subset”start index or include/exclude
“unique” and input has duplicatessort, then skip equal choices at the same depth
“sum to target”DFS with remaining target
“use a value again”recurse with the same index
“use each value once”recurse from the next index
“every ordering”choose from unused values
“all valid cuts / strings”try every next valid piece
“grid path cannot reuse a cell”mark, explore, restore
“place / assign under rules”choose a slot, maintain fast constraint sets, prune symmetry

Why this guide covers 15 of NeetCode 250’s 17 Backtracking problems

NeetCode 250 currently labels 17 questions as Backtracking. This guide keeps the 15 where backtracking is the primary pattern to learn and solve.

The two exceptions are intentionally studied elsewhere:

  • Partition to K Equal Sum Subsets — use the 1-D DP / bitmask-DP treatment. Although a brute-force search exists, the reusable interview pattern is state compression and memoization.
  • Word Break II — use memoized DFS / 1-D DP after mastering ordinary backtracking. Its important idea is caching suffix results, not just exploring a decision tree.

Trie-led Word Search II is another worthwhile follow-on after this core track.