Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    1803 - Count Pairs With XOR in a Range.

    Hard

    Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.

    A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.

    Example 1:

    Input: nums = 1,4,2,7, low = 2, high = 6

    Output: 6

    Explanation: All nice pairs (i, j) are as follows:

    • (0, 1): nums0 XOR nums1 = 5

    • (0, 2): nums0 XOR nums2 = 3

    • (0, 3): nums0 XOR nums3 = 6

    • (1, 2): nums1 XOR nums2 = 6

    • (1, 3): nums1 XOR nums3 = 3

    • (2, 3): nums2 XOR nums3 = 5

    Example 2:

    Input: nums = 9,8,4,2,1, low = 5, high = 14

    Output: 8

    Explanation: All nice pairs (i, j) are as follows:

    • (0, 2): nums0 XOR nums2 = 13

    • (0, 3): nums0 XOR nums3 = 11

    • (0, 4): nums0 XOR nums4 = 8

    • (1, 2): nums1 XOR nums2 = 12

    • (1, 3): nums1 XOR nums3 = 10

    • (1, 4): nums1 XOR nums4 = 9

    • (2, 3): nums2 XOR nums3 = 6

    • (2, 4): nums2 XOR nums4 = 5

    Constraints:

    • <code>1 <= nums.length <= 2 * 10<sup>4</sup></code>

    • <code>1 <= numsi<= 2 * 10<sup>4</sup></code>

    • <code>1 <= low <= high <= 2 * 10<sup>4</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 Integer countPairs(IntArray nums, Integer low, Integer high)
      • Methods inherited from class java.lang.Object

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