951. Maximum XOR with an Element from Array

HardTreesTrieBit ManipulationOffline Query

Given an array nums and a list of queries, each query [x, m] asks for the maximum value of x XOR nums[j] over all elements nums[j] that are <= m. If no element is <= m, the answer is -1. Return the answers as an array, one per query in order. The input is JSON {nums, queries}.

Input: JSON {nums, queries}.

Output: Array — the answer for each query.

Examples

Example 1
Input: {"nums":[0,1,2,3,4],"queries":[[3,1],[1,3],[5,6]]}
Output: [3,3,7]
Explanation: Best XOR under each limit.
Example 2
Input: {"nums":[5,2,4,6,6,3],"queries":[[12,4],[8,1],[6,3]]}
Output: [15,-1,5]
Explanation: Second query has no element <= 1.
Example 3
Input: {"nums":[10],"queries":[[5,20],[5,1]]}
Output: [15,-1]
Explanation: Limit filters the element.

Constraints

Asked by

Google
Solve this problem in the editor →