Given array of n integers. Divide this array elements and put them into 4 boxes such that sum of the XOR of all elements in all the 4 boxes combined is maximum.
Example array { 1,1,1,1,1 } will give 3 as ouput
How?
1st box : 1
2nd box : 1
3rd box : 1^1 (=0)
4th box : 1
Sum = 1+1+0+1 = 3
Solve this Problem
Mention Problem link pls
No link, got the question somewhere.
you are in problem want to distribute your array into Array (a1,a2,a3,…,an) into 4 boxes so that xor sum is maximum.
So, xor sum =( xor of elements of box 1 )+ ( xor of elements of box 2 )+( xor of elements of box 3 )+( xor of elements of box 4 )
So, in Array =(1,1,1,1,1)
Maximum was obtained when you give
Box 1=1
Box 2=1
Box 3=1
Box 4=1,1
xor sum=1 + 1 + 1 + (1^1)=1+1+1+0=3 ->answer
Hit like if u get it
Exactly, right !
And Array values are between 1 and 15,
and array range 10^4
bt u gave array elements as (1,1,1,1,1)
Answer will change if array elements are different
No, that was an example test case
you want me to optimize the logic?
No, I am looking for solution to this problem.
Given an array of positive integers. we need to find maximum xor
just use recursion or u are getting TLE by using it.
If u could give me problem link then I can try .