{"id":"fee9403d-3681-4e12-82a2-0ece72fce8e7","name":"Min Xor Pairs","description":"1. You are given an array of distinct integers.\r\n2. You have to print all pairs of integers in the array whose XOR value is minimum.","inputFormat":"A number N\r\narr1\r\narr2..\r\nN numbers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= n &lt;= 10^5\r\n-10^9 &lt;= arr[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\nvoid solution(vector<int>& arr){\n // write your code here\n}\nint main(){\n int n;\n cin>>n;\n vector<int>arr(n);\n for(int i=0;i<n;i++){\n cin>>arr[i];\n }\n \n solution(arr);\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void solution(int[] arr) {\r\n //write your code here\r\n \r\n }\r\n\tpublic static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0 ; i < n; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n solution(arr);\r\n }\r\n \r\n \r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n2\r\n0\r\n5\r\n7","sampleOutput":"0, 2\r\n5, 7\r\n","questionVideo":"https://www.youtube.com/embed/OZ2jghS0t24?end=116","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":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"29cc4611-7bf7-43d5-a3e7-829f6b4164ed","name":"Min Xor Pairs","slug":"min-xor-pairs","type":1}],"next":{"id":"56f77850-79f6-400e-991a-a0407e8f2186","name":"Min XOR Pairs MCQ","type":0,"slug":"min-xor-pairs-mcq"},"prev":{"id":"5bf8b976-ce83-43d2-ace4-1ca693dc9896","name":"Print Binary And Reverse Bits","type":3,"slug":"print-binary-and-reverse-bits"}}}

Min Xor Pairs

1. You are given an array of distinct integers. 2. You have to print all pairs of integers in the array whose XOR value is minimum.

{"id":"fee9403d-3681-4e12-82a2-0ece72fce8e7","name":"Min Xor Pairs","description":"1. You are given an array of distinct integers.\r\n2. You have to print all pairs of integers in the array whose XOR value is minimum.","inputFormat":"A number N\r\narr1\r\narr2..\r\nN numbers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= n &lt;= 10^5\r\n-10^9 &lt;= arr[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\nvoid solution(vector<int>& arr){\n // write your code here\n}\nint main(){\n int n;\n cin>>n;\n vector<int>arr(n);\n for(int i=0;i<n;i++){\n cin>>arr[i];\n }\n \n solution(arr);\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void solution(int[] arr) {\r\n //write your code here\r\n \r\n }\r\n\tpublic static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0 ; i < n; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n solution(arr);\r\n }\r\n \r\n \r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n2\r\n0\r\n5\r\n7","sampleOutput":"0, 2\r\n5, 7\r\n","questionVideo":"https://www.youtube.com/embed/OZ2jghS0t24?end=116","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":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"29cc4611-7bf7-43d5-a3e7-829f6b4164ed","name":"Min Xor Pairs","slug":"min-xor-pairs","type":1}],"next":{"id":"56f77850-79f6-400e-991a-a0407e8f2186","name":"Min XOR Pairs MCQ","type":0,"slug":"min-xor-pairs-mcq"},"prev":{"id":"5bf8b976-ce83-43d2-ace4-1ca693dc9896","name":"Print Binary And Reverse Bits","type":3,"slug":"print-binary-and-reverse-bits"}}}
plane

Editor


Loading...

Min Xor Pairs

easy

1. You are given an array of distinct integers. 2. You have to print all pairs of integers in the array whose XOR value is minimum.

Constraints

1 <= n <= 10^5 -10^9 <= arr[i] <= 10^9

Format

Input

A number N arr1 arr2.. N numbers

Output

Check the sample output and question video.

Example

Sample Input

4 2 0 5 7

Sample Output

0, 2 5, 7

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode