Sum of All Subset XOR Totals
EasyBit Manipulationbit manipulation
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
The **XOR total** of an array is the bitwise XOR of all its elements, and the XOR total of an empty array is 0.
Given an integer array nums, consider every subset of positions (so equal values at different positions count as different subsets). Return the sum of the XOR totals of all 2^n subsets.
Examples
Input: nums = [1,3]
Output: 6
Subsets: [] -> 0, [1] -> 1, [3] -> 3, [1,3] -> 2. Total 6.
Input: nums = [5,1,6]
Output: 28
The eight subset XOR totals are 0,5,1,6,4,3,7,2, which sum to 28.
Input: nums = [3,4,5,6,7,8]
Output: 480
Summing all 64 subset XOR totals gives 480.
Constraints
- 1 <= nums.length <= 12
- 1 <= nums[i] <= 20
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.