Maximum XOR with Limit
Solve a medium-level problem of finding the maximum XOR value between a number and an array with limits using bitwise tries.
Problem statement
Given an array of integers nums
and an array of queries
in the format of (x, limit)
, for every query in the form of (x, limit)
, return the maximum value of XOR between the value x
and any integer from the array such that the array element should be less than or equal to the limit
. If all elements in nums
are larger than the limit, return -1
.
Example
Sample input
Get hands-on with 1400+ tech skills courses.