Well, I found a solution with complexity O (N ^ 2 * log (MAX)) , where MAX is the largest value in the array.
Let there be 3 elements X, Y, Z from array A.
where X = A [i], Y = A [j], Z = A [k] and i! = j! = k
We need the maximum value (X ^ Y ^ Z) .
Suppose W = X * Y.
Then we would like to find a Z that gives the maximum value for W ^ Z and Z! = X and Z! = Y
Now this is reduced to the problem of finding two elements whose XOR is maximum , which can be done for a given W in O (log (MAX)) using Trie .
Explanation for Trie:
Suppose W = 10001 here is W in binary .
Now we know 1 ^ 0 = 1, 0 ^ 0 = 0, 1 ^ 1 = 0 , so we can get the maximum value for W ^ Z when Z 01110 , because W ^ Z will give = 11111 .
But in our array there is no need to have 15 or Base2 (11111) . we will use the best option possible.
So, we will create Trie of all elements of the array according to their binary representation.
If A = [1,2,7] , then 1 = 001 , 2 = 010 , 7 = 111 in binary.
Then Trie will look like this: -
Top / \ 0 1 / \ \ 0 1 1 \ / \ 1 0 1
Now let's assume W = 7 , and we want to find Z that W ^ Z is maximal (at Z = 000) , then we start with Top and see if there is a branch leading to 0, since the first bit of 7 is 1, then we will go through this branch, and then again see if we have a branch leading to 0 on the 2nd bit, again we find it, then for the last time we are looking for a branch leading to 0 on the 3rd bit, but we do not find this, so we go down through another branch, which gives us Z = 001 . Thus, the maximum of W ^ Z will be equal to 7 ^ 1 = 6 . Now the difficulty of finding Z will be the maximum height of Trie , which will be log (MAX) .
Thus, we have an N * (N-1) / 2 number W , and for each W we can find the maximum value W ^ Z , and if we take the Maximum of all the values W ^ Z , we get our answer.