XOR of a given range
Easy Accuracy: 65.89% Submissions: 5822 Points: 2

You are given an array nums. Your task is to complete the function getXor to return the XOR of the given range a and b.
 

Example 1:

Input: nums = {1, 3, 5, 7, 9, 11}
,a = 1, b = 3
Output: 1
Explanation: 3^5^7 = 1

Example 2:

Input: nums = {1, 2, 3, 4, 5}
a = 0, b = 4
Output: 1

 

Your Task:
You don't need to read or print anyhting. Your task is to comlplete the function getXor() which takes nums, a and b as input parameter and returns the xor from a to b.

 

Expected Time Complexity: O(n)
Expected Space Complexity: O(1)

 

Constraints:
1 ≤ n ≤ 105
0 ≤ a ≤ b ≤ n
1 ≤ nums[i] ≤ 100

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

XOR of a given range

Output Window