Generate All Subsets
Mediumjavapythonccppjavascript
Given an array of distinct integers, generate every subset (the power set).
Input Format
The first line contains an integer N. The second line contains N space-separated distinct integers.
Output Format
Print 2^N lines, one per subset, in order of the binary mask 0 .. 2^N - 1. For a mask, list the elements at set bit positions in index order, separated by single spaces. The empty subset is printed as an empty line.
Example 1
Input
2 1 2
Output
1 2 1 2
Explanation: Masks 00, 01, 10, 11 give the empty set, {1}, {2}, {1,2}.
- 1 <= N <= 12
- -1000000000 <= A[i] <= 1000000000