#include
#include
using namespace std;
int find_num(int max,int min)
{
int result=1;
while(max!=0)
{
max=max>>1;
result=result*2;
}
result=result/2;
if(result>=min)
return result;
else
return -1;
}
int maxXOR(int x,int y)
{
int ans1=0,ans2;
int num=find_num(y,x);
if(num!=-1)
ans1=num^(num-1);
ans2=x^y;
return max(ans1,ans2);
}
int main()
{
int x,y;
cin>>x>>y;
if(x==y)
cout<<0;
else
cout<<maxXOR(x,y);
return 0;
}
Failing for 1 test case ,please tell the problem?
@namangarg31
This was a simple question where you had to run 2 nested loop from X to Y
Calculate xor for each value in loop and find max
Please try that