Prefix xor · Medium
A diagnostic tool combines status masks using XOR over requested intervals of an event log. The log is immutable for this request. Masks use all 32 bits, so a language that represents bitwise results as signed integers must still return unsigned values.
Return the unsigned XOR of all masks in each inclusive query range in the requested order.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ nums: unsigned32[], queries: [integer, integer][] }
Fields
- nums contains unsigned 32-bit integers from 0 through 4294967295. Values with bit 31 set are positive JSON integers.
- queries is an array of inclusive zero-based [left,right] index pairs. Every pair satisfies 0 <= left <= right < nums.length.
- The values do not change between queries. If nums is empty, queries is empty. Neither input array may be modified.
Output
Return value
- Return an array of unsigned integers from 0 through 4294967295.
- Equal masks cancel in pairs. A singleton returns its mask and empty queries return [].
Constraints
- 0 <= nums.length <= 100000; 0 <= queries.length <= 100000.
- All input indexes and counts are integers.
Examples
Example 1
{
"nums": [
1,
3,
2
],
"queries": [
[
0,
2
],
[
1,
2
]
]
}Returns
[
0,
1
]Example 2
{
"nums": [
4294967295
],
"queries": [
[
0,
0
]
]
}Returns
[
4294967295
]Required complexity
O(n + q) time and O(n) auxiliary space excluding output