Common Mistakes

Common errors to avoid

  • Forgetting to backtrack (undo state): After recursive call returns, restore state to try next option. Missing this corrupts the search.
  • Not handling duplicates correctly: For inputs with duplicates, sort first and skip consecutive identical elements to avoid duplicate solutions.
  • Inefficient validity checking: Cache attack lines (columns, diagonals) in sets for O(1)O(1) checks instead of O(n)O(n) scanning.
  • Copying solution at wrong time: Add to results when solution is complete, not during construction.

Deep copy mutable objects.