Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    1707 - Maximum XOR With an Element From Array.

    Hard

    You are given an array nums consisting of non-negative integers. You are also given a queries array, where <code>queriesi = x<sub>i</sub>, m<sub>i</sub></code>.

    The answer to the <code>i<sup>th</sup></code> query is the maximum bitwise XOR value of <code>x<sub>i</sub></code> and any element of nums that does not exceed <code>m<sub>i</sub></code>. In other words, the answer is <code>max(numsj XOR x<sub>i</sub>)</code> for all j such that <code>numsj<= m<sub>i</sub></code>. If all elements in nums are larger than <code>m<sub>i</sub></code>, then the answer is -1.

    Return an integer array answer where answer.length == queries.length and answer[i] is the answer to the <code>i<sup>th</sup></code> query.

    Example 1:

    Input: nums = 0,1,2,3,4, queries = [3,1,1,3,5,6]

    Output: 3,3,7

    Explanation:

    • 0 and 1 are the only two integers not greater than 1. 0 XOR 3 = 3 and 1 XOR 3 = 2. The larger of the two is 3.

    • 1 XOR 2 = 3.

    • 5 XOR 2 = 7.

    Example 2:

    Input: nums = 5,2,4,6,6,3, queries = [12,4,8,1,6,3]

    Output: 15,-1,5

    Constraints:

    • <code>1 <= nums.length, queries.length <= 10<sup>5</sup></code>

    • queries[i].length == 2

    • <code>0 <= numsj, x<sub>i</sub>, m<sub>i</sub><= 10<sup>9</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final IntArray maximizeXor(IntArray nums, Array<IntArray> queries)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait