Tag Archives: XOR

XOR of all subarray XORs

Given an array of integers, we need to get total XOR of all subarray XORs where subarray XOR can be obtained by XORing all elements of it. Examples: Input : arr[] = [3, 5, 2, 4, 6] Output : 7 Total XOR of all subarray XORs is, (3) ^ (5) ^ (2) ^ (4) ^… Read More »

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 »