27. All Subsets XOR Sum
โ GFG solution to the All Subsets XOR Sum problem: calculate sum of XOR values across all subsets using optimal bitwise OR technique with mathematical insight. ๐
๐งฉ Problem Description
๐ Examples
Example 1
Input: arr[] = [7, 2]
Output: 14
Explanation: Subsets are: [[], [7], [2], [7, 2]]
Sum of all XOR's = 0 + 7 + 2 + (7 ^ 2) = 0 + 7 + 2 + 5 = 14.Example 2
Input: arr[] = [1, 2, 3]
Output: 12
Explanation: Subsets are: [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
Sum of all XOR's = 0 + 1 + 2 + 3 + (1 ^ 2) + (1 ^ 3) + (2 ^ 3) + (1 ^ 2 ^ 3) = 12.๐ Constraints
โ
My Approach
Bitwise OR + Left Shift Technique
๐ Time and Auxiliary Space Complexity
๐งโ๐ป Code (C++)
โ Code (Java)
๐ Code (Python)
๐ง Contribution and Support
๐Visitor Count
Last updated