shlogg · Early preview
Md Ariful Haque @mah-shamim

XOR Queries Of A Subarray In Constant Time

Compute XOR of subarray elements using prefix XOR array in O(n + q) time complexity.

1310. XOR Queries of a Subarray
Difficulty: Medium
Topics: Array, Bit Manipulation, Prefix Sum
You are given an array arr of positive integers. You are also given the array queries where queries[i] = [lefti, righti].
For each query i compute the XOR of elements from lefti to righti (that is, arr[lefti] XOR arr[lefti + 1] XOR ... XOR arr[righti] ).
Return an array answer where answer[i] is the answer to the ith query.
Example 1:

Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]
Output: [2,7,14,8]
Explanation:
The binary representation of the elements in the array are:


  1 = 0001...