Subsets, Permutations and Combinations

medium
Unit 15 · Two Pointers & Backtracking0/3 to milestone

Implement three classic backtracking generators, without using itertools:

  • subsets(items): all subsets, each keeping the original order, listed in the order produced by "include or skip each item, trying skip first"
  • permutations(items): all orderings in lexicographic order of positions (as itertools.permutations would produce them)
  • combination_sum(candidates, target): all unique combinations of positive candidates that sum to target, where each candidate can be reused. Each combination is sorted ascending, and the list of combinations is sorted.

Return lists of lists.

#backtracking#recursion2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Subsets, Permutations and Combinations · TechGradify