what is the meaning of maximum of a xor b and how to approach this problem
Xor profit problem 1
Hey Shubham,
I have solved the XOR profit problem, and I hope “XOR profit problem” and “XOR profit problem 1” are the same. You are given two numbers X and Y.
For every number between X and Y(inclusive), You have to find two numbers ‘a’ and ‘b’ such that their XOR is maximum for the given range of number and print the maximum XOR value. Focus more on finding the maximum possible value rather than finding the numbers.
hey @Shubham-Singh-1843190805727785, you have given two integers x and y, there can be many pairs of a and b such that x<=a,b<=y. You can calculate a xor b for all these pair. Out these pairs you need find that pair which gives maximum value of a xor b.
@sp160899 what can be a o(n) solution for this problem?
i can generate all the pairs that will satisfy this condition and solve this in o(n^2)
@Shubham-Singh-1843190805727785 Have a look at it
int main(){
int a,b;
cin>>a>>b;
int xr = a^b;
int msbpos=0;
while(xr){
msbpos++;
xr = xr>>1;
}
int maxxr=0;
int x=1;
while(msbpos--){
maxxr+=x;
x = x<<1;
}
cout<<maxxr;
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
hello Sir please explain the code