Search topics...
All Problems

Bitwise XOR in a Subarray

Solution Approach
Was this helpful?
MediumbitsExpected: O(n + q) time, Unknown space
prefix-sumbit-manipulation

Problem

Given an array of integers and a list of queries [left, right], return the XOR of elements from index left to right for each query.

Example 1:

Input: arr = [1, 3, 4, 8], queries = [[0, 1], [1, 2], [0, 3]]
Output: [2, 7, 14]
Explanation: 1^3=2, 3^4=7, 1^3^4^8=14

Example 2:

Input: arr = [4, 8, 2, 10], queries = [[2, 3], [1, 3]]
Output: [8, 0]
Reference solution unlocks after your first submission
Loading...