Loading...
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.
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.
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.
nums.length, queries.length ≤105queries[i].length =2nums[j], x, limit ≤109Click "Run" to test with sample cases or "Submit" to run all tests.