The code is running fine, but the two test cases are not being passed.
Here is the link of the code given below.
Doubt in XOR profit
Hello @ratulhans,
There are two mistakes in your code:
-
You are iterating both the loops from 1 to a and 1 to b resp., which is wrong.
It is mentioned in the question: x <= a <= b <= y.
Solution:
Both loops will iterate from x to y (i.e. a and b in your program)
This is because you have to find XOR of the number lying between and on x and y. -
For each iteration of loop, you are checking for the XOR of a and b, which is giving right answer for the given sample testcases.
But, the logic is incorrect.
Solution:
check for i^y
I have modified your mistakes, you can check it here:
Hope, this would help.
Give a like, if you are satisfied.
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.