C#. 528 ms. Brute force with exit optimization. Not the best solution.
The answer cannot be larger than the biggest number with all bits set to the right of the highest set bit. So... sort the array descending, run a brute force co
The answer cannot be larger than the biggest number with all bits set to the right of the highest set bit. So... sort the array descending, run a brute force comparison, quit when your maximum is larger than any possible remaining maximum. You can create a test case that causes dismal performance.\n\n```\n\npublic class Solution {\n    \n    public int SetAllBitsToRightOfHighest(int num){\n        num |= num >> 1;\n        num |= num >> 2;  \n        num |= num >> 4; \n        num |= num >> 8;\n        num |= num >> 16;\n        return num;\n    }\n    \n    public int FindMaximumXOR(int[] nums) {\n        \n        Array.Sort(nums, (a, b) => b - a);\n        \n        int answer = 0;\n        for(int i = 0; i < nums.Length; i++){\n            if(answer >= SetAllBitsToRightOfHighest(nums[i])) break;\n            for(int j = i + 1; j < nums.Length; j++){\n                int test = nums[i] ^ nums[j];\n                if(test > answer) answer = test;\n            }\n        }\n        \n        return answer;\n    }    \n    \n}\n```\n
[]