Ctrl K

Even Bits Across Three Lists

Medium
You are given three arrays of non-negative integers first, second and third. Take one element from each, first[i], second[j] and third[k], and compute their bitwise XOR. Return the number of index triples (i, j, k) for which that XOR has an **even** number of set bits in binary (zero set bits counts as even).
Example 1
first=[5], second=[6], third=[3] → 1

5 ^ 6 ^ 3 = 0, which has zero set bits, an even number. The answer is 1.

Example 2
first=[1, 2], second=[4], third=[0, 7] → 2

Check all four: 1 ^ 4 ^ 0 = 5 (two bits, yes), 1 ^ 4 ^ 7 = 2 (one bit, no), 2 ^ 4 ^ 0 = 6 (two bits, yes), 2 ^ 4 ^ 7 = 1 (no). The answer is 2.

Example 3
first=[3, 8, 0], second=[1, 1], third=[12, 5, 9] → 6
Constraints
  • 1 ≤ len(first), len(second), len(third) ≤ 10⁵
  • 0 ≤ first[i], second[i], third[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsEvery Topping Combo MediumAll Distinct Card Hands MediumThe Odd One Among Triples MediumTwo Values Without a Pair MediumSpot the Extra Copy Medium
loading Python…
Input
first=[5], second=[6], third=[3]
Expected
1

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