SOARDO
Software Engineer (SDE)dsaintermediate3 interactive MCQs in app

Backtracking: Subsets, Permutations & N-Queens

choose-explore-unchoose state restorationpath[:] copy trap when recording resultsstart index vs used[] boolean array for subsets vs permutations

Backtracking explores a decision tree recursively via **Choose -> Explore -> Unchoose (`pop` / undo mutation)**, pruning invalid branches early instead of enumerating blind brute force. For `Subsets` (`O(n * 2^n)`), pass `start` index (`for i in range(start, len(nums))`) to avoid duplicate sets; when storing `path`, ALWAYS append a snapshot copy `res.append(path[:])`!

for `subsets([1, 2])`, choose `1` -> save `[1]`, choose `2` -> save `[1, 2]`, unchoose `2` (`pop()`), unchoose `1` (`pop()`), then choose `2` -> save `[2]`.
(classic!) doing `res.append(path)` without copying appends references to the SAME mutating list, ending up with `[[], [], [], ...]`!
Backtracking — GeeksforGeeksread ↗Backtracking: Subsets, Permutations & N-Queens — Applied Practicepractice ↗VisuAlgo Interactive Visualizationsvisualize ↗NeetCode DSA Roadmappractice ↗

Practice Backtracking: Subsets, Permutations & N-Queens with 3 graded MCQs & written feedback.

Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.

Test yourself free on SOARDO →View full Software Engineer roadmap

More Software Engineer Study Guides