Practice XOR Queries of a Subarray
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
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.
Source: XOR Queries of a Subarray on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]
Output
[2,7,14,8]
# Example 2
Input
arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]
Output
[8,0,4,4]
Constraints
1 <= arr.length, queries.length <= 3 * 10^4
1 <= arr[i] <= 10^9
queries[i].length == 2
0 <= lefti <= righti < arr.length
Related LeetCode Problems
Practice more problems similar to XOR Queries of a Subarray.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.