MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / find_max_xor

Function find_max_xor

HackerEarth_problems/Subarrays XOR/Solution.cpp:85–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85int find_max_xor(trienode* head,int val,int k)
86{
87 int value=val;
88 trienode* curr=head;
89 int ans=0;
90 for(int j=20;j>=0;j--)
91 {
92 int b=(value>>j)&1;//present value
93 int q=(k>>j)&1;// kth value
94 //cout<<b<<" ";
95 if(q==1 && b==1)
96 {
97 ans+=curr->countr;
98 if(!curr->left)
99 return ans;
100 curr=curr->left;
101 }
102 else if(q==1 && b==0)
103 {
104 ans+=curr->countl;
105 if(!curr->right)
106 return ans;
107 curr=curr->right;
108 }
109 else if(q==0 && b==1)
110 {
111 if(!curr->right)
112 return ans;
113 curr=curr->right;
114 }
115 else if(q==0 && b==0)
116 {
117 if(!curr->left)
118 return ans;
119 curr=curr->left;
120 }
121 }
122 return ans;
123}
124int main()
125{
126 int n,p=0,t,k;

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected