[C++], Trie solution,with explanation
Before directly Jumping in the code first go through the explantion given at the last,otherwise it would be difficult for you to understand\n\nclass Solution {\
**Before directly Jumping in the code first go through the explantion given at the last,otherwise it would be difficult for you to understand**\n```\nclass Solution {\npublic:\n    struct Trie{\n        Trie* children[2];\n        Trie()\n        {\n            for(int i=0;i<2;i++)\n                this->children[i]=NULL;\n        }\n    };\n    Trie* Node=new Trie();\n    void Insert(string &s)\n    {\n        int i,n=s.length();\n        Trie* temp=Node;\n        for(i=0;i<n;i++)\n        {\n            if(temp->children[s[i]-\'0\']==NULL)\n            {\n                Trie* temp2=new Trie();\n                temp->children[s[i]-\'0\']=temp2;\n            }\n            temp=temp->children[s[i]-\'0\'];\n        }\n    }\n    int Search(string &s)\n    {\n        int i,n=s.length();\n        Trie* temp=Node;\n        int ans=0;\n        for(i=0;i<n;i++)\n        {\n            if(temp->children[abs(s[i]-\'0\'-1)]!=NULL)\n            {\n                ans=2*ans+1;\n                temp=temp->children[abs(s[i]-\'0\'-1)];\n            }\n            else\n            {\n                ans=2*ans;\n                temp=temp->children[s[i]-\'0\'];\n            }\n        }\n        return ans;\n    }\n    int findMaximumXOR(vector<int>& nums) \n    {\n        int n=nums.size(),i;\n        string S[n];\n        for(i=0;i<n;i++)\n        {\n            int a=nums[i];\n            while(a!=0 || S[i].length()<31)\n            {\n                S[i]+=(\'0\'+a%2);\n                a/=2;\n            }\n        }\n        for(i=0;i<n;i++)\n        {\n            reverse(S[i].begin(),S[i].end());\n        }\n        Insert(S[0]);\n        int m=0;\n        for(i=1;i<n;i++)\n        {\n            m=max(m,Search(S[i]));\n            Insert(S[i]);\n        }\n        return m;\n    }\n};\n```\nAnalysis from the question:\n1.For all the numbers for the array,take a number **X**,Let\'s consider the **X** in bitwise and From the highest bit of **X**=>**i** to lowest bit 0. The remaining numbers Can be divided into two set one with set(1) bit at the bit position i and the other with unset(0) bit at the bit position i,If the bit in the ith position of X is set then we would consider all the numbers with unset bit and neglect the other half similar for when ith bit in the X being unset.\n2.Now to implement the above logic we need to use Trie.\n3. We need the pre-proccessing of all the numbers,such that they contain same number of bit as you can see in the code.\n4.Now we need to insert the bonary representation of each number.\n5.Now serching the highest value for the ith number,with (i-1)numbers already inserted.\n\n\nIf you have any doubt or feel that you need somewhat more explanation of any portion then leave a comment with the portion,I will try best to Update ASAP.Also Upvote this if you find this helpful.
['Trie']