1312. Pairs with XOR Equal to K

EasyBit ManipulationBit ManipulationXORHashing

Given an array of integers and an integer k, count the number of index pairs (i, j) with i < j such that nums[i] XOR nums[j] equals k.

Input: A JSON object {"nums": [<integers>], "k": <integer>}.

Output: Return the number of unordered pairs whose XOR equals k.

Examples

Example 1
Input: {"nums":[1,2,3,4,5],"k":1}
Output: 2
Explanation: Pairs (2,3) and (4,5) XOR to 1 -> 2.
Example 2
Input: {"nums":[3,3,3],"k":0}
Output: 3
Explanation: All three equal values form 3 pairs XOR-ing to 0 -> 3.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →