For n is greater than one, our task becomes to choose those numbers from the array whose bitwise AND leads to an only single bit set number. To do so, we search a position, at which all elements in the set has a bit set at that position. For example, for set { 4 (100), 6 (110), 7 (111) }, at position 2 (from right to left, 0-based indexing) bit is set for all element. So, doing bitwise AND gives 4, which is a power of 2.
Illustration :
12 --> 01100
13 --> 01101
7 --> 00111
For position = 0(from right to left, 0-based indexing), there exist 13 and 17 whose bit is setbit.
total --> 1111111111111111111111
13 --> 0000000000000000001101
7 --> 0000000000000000000111
-----------------------------
bitwise AND --> 0000000000000000000101
bitwise AND is not power of 2 so it is not a valid subset.
For position = 1, there exist only 7 whose bit is setbit.
total --> 1111111111111111111111
7 --> 0000000000000000000111
------------------------------
bitwise AND --> 0000000000000000000111
bitwise AND is not power of 2 so it is not a valid subset.
For position = 2, there exist 12, 13 and 7 whose bit is setbit.
total --> 1111111111111111111111
12 --> 0000000000000000001100
13 --> 0000000000000000001101
7 --> 0000000000000000000111
------------------------------
bitwise AND --> 0000000000000000000100
bitwise AND is power of 2 so it is a valid subset.
Similarly, we can check for remaining positions.