Ctrl K

XOR of All Triple Mixes

Medium
You are given an integer array values of length n. For any triple of indices (i, j, k), each from 0 to n - 1 and allowed to repeat, define its mix as (values[i] | values[j]) & values[k] where | is bitwise OR and & is bitwise AND. There are n³ triples in total. Return the bitwise XOR of the mixes of all of them.
Example 1
values=[3, 5] → 6

There are 2³ = 8 triples: (3|3)&3 = 3, (3|3)&5 = 1, (3|5)&3 = 3, (3|5)&5 = 5, (5|3)&3 = 3, (5|3)&5 = 5, (5|5)&3 = 1, (5|5)&5 = 5. The XOR of all eight is 6.

Example 2
values=[12] → 12

The only triple (0, 0, 0) gives (12 | 12) & 12 = 12.

Example 3
values=[7, 7, 2] → 2
Constraints
  • 1 ≤ len(values) ≤ 10⁵
  • 1 ≤ values[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Bit Differences MediumEight Lamps After Many Nights MediumSplit Into Equal-XOR Halves MediumTake From Any Pile MediumSwitch Lines to Darken the Board Medium
loading Python…
Input
values=[3, 5]
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.