710. XOR of numbers in a given range

Given two integers L and R. Find the XOR of the elements in the range [L , R].

Example 1:

Input : L = 3 , R = 5

Output : 2

Explanation : answer = (3 ^ 4 ^ 5) = 2.

Example 2:

Input : L = 1, R = 3

Output : 0

Explanation : answer = (1 ^ 2 ^ 3) = 0.

Now Your Turn!

Pick the correct output for the given input

Input : L = 4, R = 10

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= L <= R <= 109

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution{
public:
int findRangeXOR(int l,int r){
//your code goes here
}
};
Test Case

Input:

L
R