title: Three elements in array whose xor is maximum
body: <p>I want to know a algorithm to find out the maximum xor value of three elements of an array.
  I have read about the <a href="https://stackoverflow.com/questions/9320109/two-elements-in-array-whose-xor-is-maximum">maximum xor for two elements</a> from an array but cannot understand how to apply it on finding the maximum value of XOR taking 3 elements of an array . Can someone point out a hint ?</p>
  
  <p><strong>Required complexity :</strong> less than <strong>O(N^3)</strong> where <strong>N</strong> is the number of elements in the array.</p>
  
  <p>Example:</p>
  
  <p><strong>A = [1,2,3,4]</strong></p>
  
  <p>All Possible Triplets :-</p>
  
  <p><strong>1^2^3 = 0</strong> <br>
  <strong>1^2^4 = 7</strong> <br>
  <strong>1^3^4 = 6</strong> <br>
  <strong>2^3^4 = 5</strong> <br></p>
  
  <p>Thus, the maximum XOR value is 7.</p>
  
  <p><strong>Edit :</strong> </p>
  
  <p>I have thought of a  solution having complexity <strong>O(N^2 * log(MAX))</strong> and it has solved my purpose :D . </p>
  
  <p><strong>MAX</strong> = Maximum Value in the Array</p>