why i m getting test cases wrong …i m getting correct outputs on some custom inputs that i’ve tried…?
XOR profit problem
hey @nikhilmeena! Your code is just basically returning the XOR of L and R but you have to find the maximum, here’s the code with mistakes commented out:
#include
using namespace std;
int main () {
int x,y,res=0;
cin>>x>>y;
int ans=x^y;
int p=1;
int positionOfLastBit=0;
while(ans>0)
{ /*int last_bit=ans&1;
if(last_bit==1)
{
res=res+(ans&1)p;
}
p=p<<1;/
positionOfLastBit++;
ans=ans>>1;
}
while(positionOfLastBit–){
res += p;
p = p<<1;
}
cout<<res;
return 0;
}
Kindly resolve this if it works and rate the reply! Thanks!