You are given an array nums of non-negative integers and an array queries, where queries[i] = [x, limit].
For query i, consider only the elements of nums that are at most limit. Return the largest value of x XOR v over those elements. If every element of nums exceeds limit, the answer for that query is -1.
Return an array answer of the same length as queries, where answer[i] is the answer to query i, in the same order the queries were given.
Examples
Example 1
Input: nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]
Output: [3,3,7]
Explanation: For [3,1] only 0 and 1 are allowed, and 3 XOR 0 = 3 is the larger value. For [1,3] the values 0 through 3 are allowed and 1 XOR 2 = 3 is best. For [5,6] every value is allowed and 5 XOR 2 = 7 is best.
Example 2
Input: nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]
Output: [15,-1,5]
Explanation: For [8,1] no element is at most 1, so the answer is -1.
Constraints
1≤nums.length, queries.length≤105
queries[i].length=2
0≤nums[j], x, limit≤109
Examples
Example 1
Input
nums = [0, 1, 2, 3, 4]
queries = [[3, 1], [1, 3], [5, 6]]
Output
[3, 3, 7]
Example 2
Input
nums = [5, 2, 4, 6, 6, 3]
queries = [[12, 4], [8, 1], [6, 3]]
Output
[15, -1, 5]
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 2
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run