C++ | Simple Math | 15 Line solution
\n// Solution is simple but the problem is we can\'t travel whole \'j\' for a particular \'i\'.\n// So whyn\'t make some condition so than we already know after
```\n// Solution is simple but the problem is we can\'t travel whole \'j\' for a particular \'i\'.\n// So whyn\'t make some condition so than we already know after this, optimal answer will not exist.\n\n//Algo :\n//Step 1 : Sort the array in decreasing order so that larger number comes first. \n//Step 2 : Think if we make all bits of nums[i] to 1 and still our answer is already greater than this one, \n//then there is no need to run further as other elements are smaller than current one!!!! \n\n//i.e. for nums[i] = 10, if we make all the bits to 1 then it will be 15(1010 --> 1111) and if we already has a answer  greater than 15, \n//then there is not need to run further  and stop the algo at that time.\n\nclass Solution {\npublic:\n    int findMaximumXOR(vector<int>& nums) {\n        sort(nums.begin(), nums.end(), greater<int>());\n        int n = nums.size();\n        int ans=0;\n        for(int i=0; i<n and ans<pow(2,floor(log2(nums[i])+1))-1; i++){\n            for(int j=i; j<n; j++){\n                ans = max(ans, nums[i]^nums[j]);\n            }\n        }\n        return ans;        \n    }\n};\n```
['Math', 'Sorting']