`{"id":"074644d3-0141-4323-9343-43fc6be0814a","name":"Count Pairs With Xor In A Range","description":"Given an integer array nums and two integers low and high.\r\nCount number of pairs of indexes (i, j) for which both of this expression's are satisfied:\r\n1. 0 <= i < j < nums.length\r\n2. low <= nums[i] ^ nums[j] <= high","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= nums.length &lt;= 2 * 10^4\r\n2. 1 &lt;= nums[i] &lt;= 2 * 10^4\r\n3. 1 &lt;= low &lt;= high &lt;= 2 * 10^4","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n \n int countPairs(vector<int> nums, int low, int high) {\n // Write your code here \n }\n\n int main()\n {\n\n int n;\n cin>>n;\n\n vector<int> nums(n,0);\n\n for (int i = 0; i < n; i++) \n {\n cin>>nums[i];\n }\n int low;\n cin>>low;\n int high;\n cin>>high;\n\n int result = countPairs(nums, low, high);\n cout<<result<<endl;\n\n }"},"java":{"code":"import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static int countPairs(int[] nums, int low, int high) {\n return 0;\n }\n\n public static void main(String[] args) throws Exception {\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\n\n int n = Integer.parseInt(read.readLine());\n\n int[]nums = new int[n];\n\n for (int i = 0; i < n; i++) {\n nums[i] = Integer.parseInt(read.readLine());\n }\n int low = Integer.parseInt(read.readLine());\n int high = Integer.parseInt(read.readLine());\n\n int result = countPairs(nums, low, high);\n System.out.println(result);\n\n }\n}\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n1\r\n4\r\n2\r\n7\r\n3\r\n5\r\n","sampleOutput":"4\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"4b4725b5-4896-4b68-aae2-03ea1e2ecbb2","name":"Trie For Intermediate","slug":"trie-for-intermediate-9996","type":0},{"id":"b201a86d-071a-4b9a-b53d-f9d539132cb5","name":"Count Pairs With Xor In A Range MCQ","slug":"count-pairs-with-xor-in-a-range-mcq","type":0},{"id":"63bf4b14-2ee1-4b46-b0bf-587f0734ee0c","name":"Count Pairs With Xor In A Range","slug":"count-pairs-with-xor-in-a-range","type":1}],"next":null,"prev":null}}`

# Count Pairs With Xor In A Range

Given an integer array nums and two integers low and high. Count number of pairs of indexes (i, j) for which both of this expression's are satisfied: 1. 0 <= i < j < nums.length 2. low <= nums[i] ^ nums[j] <= high

`{"id":"074644d3-0141-4323-9343-43fc6be0814a","name":"Count Pairs With Xor In A Range","description":"Given an integer array nums and two integers low and high.\r\nCount number of pairs of indexes (i, j) for which both of this expression's are satisfied:\r\n1. 0 <= i < j < nums.length\r\n2. low <= nums[i] ^ nums[j] <= high","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. 1 &lt;= nums.length &lt;= 2 * 10^4\r\n2. 1 &lt;= nums[i] &lt;= 2 * 10^4\r\n3. 1 &lt;= low &lt;= high &lt;= 2 * 10^4","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n \n int countPairs(vector<int> nums, int low, int high) {\n // Write your code here \n }\n\n int main()\n {\n\n int n;\n cin>>n;\n\n vector<int> nums(n,0);\n\n for (int i = 0; i < n; i++) \n {\n cin>>nums[i];\n }\n int low;\n cin>>low;\n int high;\n cin>>high;\n\n int result = countPairs(nums, low, high);\n cout<<result<<endl;\n\n }"},"java":{"code":"import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static int countPairs(int[] nums, int low, int high) {\n return 0;\n }\n\n public static void main(String[] args) throws Exception {\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\n\n int n = Integer.parseInt(read.readLine());\n\n int[]nums = new int[n];\n\n for (int i = 0; i < n; i++) {\n nums[i] = Integer.parseInt(read.readLine());\n }\n int low = Integer.parseInt(read.readLine());\n int high = Integer.parseInt(read.readLine());\n\n int result = countPairs(nums, low, high);\n System.out.println(result);\n\n }\n}\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"4\r\n1\r\n4\r\n2\r\n7\r\n3\r\n5\r\n","sampleOutput":"4\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"4b4725b5-4896-4b68-aae2-03ea1e2ecbb2","name":"Trie For Intermediate","slug":"trie-for-intermediate-9996","type":0},{"id":"b201a86d-071a-4b9a-b53d-f9d539132cb5","name":"Count Pairs With Xor In A Range MCQ","slug":"count-pairs-with-xor-in-a-range-mcq","type":0},{"id":"63bf4b14-2ee1-4b46-b0bf-587f0734ee0c","name":"Count Pairs With Xor In A Range","slug":"count-pairs-with-xor-in-a-range","type":1}],"next":null,"prev":null}}` Editor

# Count Pairs With Xor In A Range

medium

Given an integer array nums and two integers low and high. Count number of pairs of indexes (i, j) for which both of this expression's are satisfied: 1. 0

## Constraints

1. 1 <= nums.length <= 2 * 10^4 2. 1 <= nums[i] <= 2 * 10^4 3. 1 <= low <= high <= 2 * 10^4

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 1 4 2 7 3 5 ```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}4 ```

Discussions

Show Discussion

Related Resources 