I want to find the sum of OR of subsets of an Array.
For example
{2,3,1}
The possible subsets are
{} --> 0
{1} -->1
{3} -->3
{2} -->2
{1,2} -->1 | 2 --> 3
{1,3} -->1 | 3 --> 3
{2,3} -->2 | 3 --> 3
{1,2,3} -->(1 | 2) |3 --> 3
Hence the sum is 18.
I tried to find all possible subsets and find bitwise OR for each subset, the add them. But the time complexity is too much. Could you please help to figure out if there is a better way to do it?