Skip to main content

πŸ”™ Backtracking

Backtracking is DFS through a decision tree. Choose, explore, unchoose. If you can describe the problem as "build a solution piece by piece, backtracking when stuck", this is the right tool.

This category contains 16 problems. Use the patterns below to recognize what's being asked, then jump to the problem list at the bottom.


🧠 Key Patterns​

  • Subsets / Power Set β€” Include or exclude each element.
  • Permutations β€” Used-set tracking; swap-in-place variant for O(1)O(1) extra space.
  • Combinations / Combination Sum β€” Start index parameter prevents repeats.
  • Word Search / Path in Grid β€” Mark cell visited, recurse, unmark.
  • N-Queens / Sudoku β€” Constraint-satisfaction with placement validation.
  • Partitioning β€” Palindrome partitioning, IP addresses β€” try every split point.

⚠️ Common Pitfalls​

  • Forgetting to "unchoose" β†’ results pollute across branches.
  • Copying the current state into results without deep-copying (new List<int>(current)).
  • Missing pruning conditions β†’ TLE on Hard problems.

πŸ“š Study Resources​

πŸ“Ί Videos​

πŸ“– Books​

🌐 Articles & References​


πŸ’» All Backtracking Problems​