Tag Archives: XOR

Count all pairs of an array which differ in K bits

Given an array of size n and integer k, count all pairs in array which differ in exactly K bits of binary representation of both the numbers. The input arrays have elements with small values and possibly many repetitions. Input: arr[] = {2, 4, 1, 3, 1} k = 2 Output: 5 Explanation: There are… Read More »

Sum of XOR of all possible subsets

Given an array arr[] of size n, we need to find sum of all the values that comes from XORing all the elements of the subsets. Input : arr[] = {1, 5, 6} Output : 28 Total Subsets = 23 1 = 1 5 = 5 6 = 6 1 ^ 5 = 4 1… Read More »