Loading problem...
You are given an integer array elements containing distinct values. Your task is to compute and return the complete power set of this array — that is, every possible collection of items that can be formed by selecting zero or more elements from the original array.
The power set is a fundamental concept in combinatorics and set theory, representing all possible combinations of elements. For an array of n distinct elements, the power set contains exactly 2ⁿ subsets, ranging from the empty set (selecting nothing) to the full set (selecting everything).
Key Requirements:
This problem tests your understanding of recursive enumeration, bit manipulation techniques, and the mathematical properties of combinatorial structures.
elements = [1,2,3][[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]For an array with 3 elements, we generate 2³ = 8 subsets. These include: the empty set [], three single-element subsets [1], [2], [3], three two-element subsets [1,2], [1,3], [2,3], and the complete set [1,2,3]. Every possible combination of inclusion/exclusion for each element is represented.
elements = [0][[],[0]]For a single-element array, the power set contains exactly 2¹ = 2 subsets: the empty set [] (excluding the element) and the set [0] (including the element).
elements = [1,2][[],[1],[2],[1,2]]For two elements, we have 2² = 4 possible subsets: exclude both [], include only first [1], include only second [2], or include both [1,2].
Constraints