Largest XOR under a cap
You get a list nums of non-negative integers and a list of queries, each [x, cap]. For each query, return the largest value of x ^ v (bitwise XOR) over the numbers v of nums with v ≤ cap, or -1 if no number is that small. Answer the queries in the order given.
nums has at least one number, all values are below 2³⁰, and queries may be empty. With thousands of numbers and queries, scanning nums for every query is too slow: aim for O((n + q) · bits) after sorting.
Besides the tests, one large input (7,500 numbers, 7,500 queries) with a ~1000 ms limit (scaled to your device's speed): brute force won't pass.
Examples
max_xor_capped([6,13,4,22,1,9], [[5,10],[5,3],[5,0],[12,30]])→[12,4,-1,26]max_xor_capped([7,1,4], [[2,0],[2,4],[6,100]])→[-1,6,7]max_xor_capped([6], [[1,6],[1,5]])→[7,-1]