Can you please suggest a better way to do it

Hi,

I am getting the output and my code has been accepted but the code looks pretty pathetic.

Can you please suggest someway where I can bring it down from O(n2) to O(n).

#include <bits/stdc++.h>
using namespace std;
int main () {
int x,y;
cin>>x>>y;
int ans=0;
for(int i=x;i<=y;i++)
{
for(int j=i;j<=y;j++)
{
if((i^j)>ans)
{
ans=i^j;
}
}
}
cout<<ans;
return 0;
}

Hello @suhaib0900 you have to do this question using TRIE data structure.
With that data structure you can solve it in more optimised way.
There must be editorial for this solving with TRIE in your course.

I don’t know what TRIE is I still have a lot of modules to go before I reach TRIE. I will come back to it when I learn TRIE.

Thanks a lot. You can close the thread.

@suhaib0900 yes sure.

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.