MAX XOR Pair using Tries C++
left pointer denotes a zero and right denotes a one.\n\n\nclass Node{\n   \n    public:\n     Node*left;\n    Node*right;   \n};\n\nclass Solution {\npublic:\n 
left pointer denotes a zero and right denotes a one.\n```\n\nclass Node{\n   \n    public:\n     Node*left;\n    Node*right;   \n};\n\nclass Solution {\npublic:\n    \n    \n    void insert(int a,Node*root){\n        \n         Node*curr=root;\n        \n         for(int i=31;i>=0;i--){\n              int last_bit=(a>>i) &1;\n               if(last_bit==0){\n\n                 if(curr->left==NULL){\n                     \n                     curr->left=new Node();\n                     \n                 }\n                   curr=curr->left;\n               \n               \n               }else{\n                   if(curr->right==NULL){\n                       curr->right=new Node();\n                   }\n                   curr=curr->right;\n               }\n         }\n        return;\n        \n    }\n    \n    \n    \n    int max_xor(int a,Node*root,vector<int> nums){\n        Node*curr=root;\n        int max_xor_val=INT_MIN;\n        int curr_xor=0;\n        for(int i=31;i>=0;i--){\n            \n            int last_bit=(a>>i)&1;\n            if(last_bit==0){\n                //if bit is 0 then we try to look for a bit which is 1 in the trie to maximize xor\n                if(curr->right){\n                    curr=curr->right;\n                    curr_xor+=(int)pow(2,i);\n                }else{\n                    curr=curr->left;\n                }\n                \n            }else{\n\t\t\t//if bit is 1 then we try to look for a bit which is 0 in the trie to maximize xor\n                if(curr->left){\n                    curr=curr->left;\n                    curr_xor+=(int)pow(2,i);\n                }else{\n                    curr=curr->right;\n                }\n            }\n        }\n        max_xor_val=max(curr_xor,max_xor_val);\n        return max_xor_val;    \n    }\n    \n    \n    int findMaximumXOR(vector<int>& nums) {\n        Node*root=new Node();\n        int n=nums.size();\n        int result=INT_MIN;\n        if(n==0){\n            return 0;\n        }\n        for(int i=0;i<n;i++){\n          insert(nums[i],root);\n          int ans=max_xor(nums[i],root,nums);\n          result=max(result,ans);\n        \n        }\n        return result;\n    }\n};\n```
[]