Subarray XOR Queries

Implement subarrayXorQueries

You're given an array nums and a batch of range queries, each one a pair [l, r]. For every query, return the XOR of every value in nums from index l through r inclusive — one answer per query, in the order the queries were given. Answering each query by walking its range works, but ranges across different queries overlap constantly. A single pass that builds a running XOR up to every index first turns each query into a lookup: XOR the running total up to r with the running total up to l − 1, and everything outside [l, r] cancels itself out completely.

Example 1:

Input: nums = [5,2,7,1,9], queries = [[0,2],[1,4],[2,2]]

Output: [0,13,7]

Example 2:

Input: nums = [0,1,2,3,4], queries = [[0,4]]

Output: [4]

Example 3:

Input: nums = [6], queries = [[0,0]]

Output: [6]

+ 7 hidden test cases run on Submit.

Constraints:

  • 1 ≤ nums.length ≤ 3 × 10⁴
  • 1 ≤ queries.length ≤ 3 × 10⁴
  • 0 ≤ l ≤ r ≤ nums.length − 1 for every query
  • 0 ≤ nums[i] ≤ 10⁵

nums =

[5, 2, 7, 1, 9]

queries =

[[0,2], [1,4], [2,2]]