Tap here to switch tabs
Problem
Submissions

Problem: Maximum XOR With an Element From Array

med
30 min
Try to solve the Maximum XOR With an Element From Array problem.

Statement

You are given an array nums consisting of non-negative integers. You are also given a 22D array queries, where queries[i] = [x_i, m_i].

The answer to the iextthi^{ ext{th}} query is the maximum bitwise XOR value of x_i with any element in nums that is less than or equal to m_i. Formally, the answer is the maximum value of nums[j] ⊕\oplus x_i for all indices j such that nums[j] ≤\leq m_i. If every element in nums is strictly greater than m_i, the answer to that query is −1-1.

Return an array containing the results of all queries in the corresponding order.

Constraints:

  • 1≤1 \leq nums.length, queries.length ≤105\leq 10^5

  • queries[i].length =2= 2

  • 0≤0 \leq nums[j], x_i, m_i ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum XOR With an Element From Array

med
30 min
Try to solve the Maximum XOR With an Element From Array problem.

Statement

You are given an array nums consisting of non-negative integers. You are also given a 22D array queries, where queries[i] = [x_i, m_i].

The answer to the iextthi^{ ext{th}} query is the maximum bitwise XOR value of x_i with any element in nums that is less than or equal to m_i. Formally, the answer is the maximum value of nums[j] ⊕\oplus x_i for all indices j such that nums[j] ≤\leq m_i. If every element in nums is strictly greater than m_i, the answer to that query is −1-1.

Return an array containing the results of all queries in the corresponding order.

Constraints:

  • 1≤1 \leq nums.length, queries.length ≤105\leq 10^5

  • queries[i].length =2= 2

  • 0≤0 \leq nums[j], x_i, m_i ≤109\leq 10^9