Given an array arr and queries where queries[i] = [left, right], return the XOR of elements from arr[left] to arr[right] for each query.
Precompute prefix XOR array where prefix[i] = arr[0] XOR arr[1] XOR ... XOR arr[i-1]. Then XOR of arr[l..r] = prefix[r+1] XOR prefix[l].
- Build prefix XOR: prefix[0]=0, prefix[i]=prefix[i-1]^arr[i-1].
- For each query [l, r]: answer = prefix[r+1] ^ prefix[l].
- This works because a^a=0, so all elements before index l cancel out.
- Time Complexity: O(N + Q)
- Space Complexity: O(N) for prefix array