Generate All Subsets

Problem Generate all subsets (the power set) of a given collection via backtracking.

Input / Output

  • Input: array (assume distinct; ask about duplicates). Output: all 2^n subsets.

Constraints

  • n <= ~16 (output exponential); with duplicates, output must skip repeated subsets (Subsets II).

Example

  • [1,2,3] → [[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]].
asked …
LeaderboardSalaryAccount