


arr=[3,4,5]
subsets ={3}, {3,4}, {3,4,5}, {3,5}, {4}, {4,5}, {5}
The first line contains a single integers ‘N’ denoting the length of the array.
The second line contains ‘N’ integers denoting the array elements.
The output contains each subset in a separate line.
You don’t need to print anything. Just implement the given function.
One of the standard and useful method of finding the power set is through bit-masking.
Consider a number with N-bits in its binary representation, if we consider that the state of ith bit depicts whether the ith array element is included in the current subset or not, then we can uniquely identify one of the subsets (as each number has a different binary representation).
Now we can simply iterate from 1 to 2n-1, each number in this iteration will define a subset uniquely. To generate the subset just check for the bits that are ON in binary representation on the number, and for each ON bit, we will simply include an array element corresponding to its position.
Remember to not include an empty subset in the final answer.
The steps are as follows :
Each element has 2 choices, it can either be included or excluded.
Using backtracking we can create all the possible subsets, we can add the current element to the temporary array and make a recursive call for the next element, when the function call returns we remove the current element from the temporary array and again make a recursive call for the next element (standard backtracking approach).
Each time we reach the end of the array, we will add the temporary array to the answer.
The steps are as follows :
Maximum Island Size in a Binary Tree
Equal Subtree Sums
Sorted Doubly Linked List to Balanced BST
Longest Substring with K-Repeating Characters
Expression Add Operators