How to get a largest subset where the xor operation between the elements of that subset is equal to k?

84 Views Asked by At

A List and k are given inputs

Let's take list [1, 2, 3, 4, 5] so the subsets obtained by XORing equal to k => 7 are {2, 5}, {1, 2, 4}, and {3, 4}. I want to print {1, 2, 4} where this subset count is largest among all other subsets.

one more example. list = [1, 2, 3, 4, 7] the subsets obtained by XORing equal to k => 0 are {1, 2, 4, 7} and {1, 2, 3} i want to print {1, 2, 4, 7}.

What is the efficient way to solve this, Anyone please help with this ?