Count Triplets with Even XOR Set Bits II - Problem
Given three integer arrays a, b, and c, return the number of triplets (a[i], b[j], c[k]) such that the bitwise XOR between the elements of each triplet has an even number of set bits.
A set bit is a bit that is equal to 1. The bitwise XOR of three numbers x, y, and z is x ^ y ^ z.
For example, if a = [1, 2], b = [3], and c = [4, 5], we need to check all possible triplets: (1, 3, 4), (1, 3, 5), (2, 3, 4), and (2, 3, 5). Count how many of these triplets have an even number of set bits in their XOR result.
Input & Output
Example 1 — Basic Case
$
Input:
a = [1, 2], b = [3], c = [4, 5]
›
Output:
2
💡 Note:
Triplets: (1,3,4)→1^3^4=6 (110₂, 2 bits even✓), (1,3,5)→1^3^5=7 (111₂, 3 bits odd✗), (2,3,4)→2^3^4=5 (101₂, 2 bits even✓), (2,3,5)→2^3^5=4 (100₂, 1 bit odd✗). Answer is 2.
Example 2 — Single Elements
$
Input:
a = [1], b = [2], c = [3]
›
Output:
1
💡 Note:
Only one triplet (1,2,3): 1^2^3 = 0 (000₂, 0 bits even✓), so answer is 1
Example 3 — All Even Parity
$
Input:
a = [0, 3], b = [5], c = [6]
›
Output:
2
💡 Note:
Triplets: (0,5,6)→0^5^6=3 (011₂, 2 bits even✓), (3,5,6)→3^5^6=0 (000₂, 0 bits even✓). Both valid, answer is 2
Constraints
- 1 ≤ a.length, b.length, c.length ≤ 104
- 0 ≤ a[i], b[j], c[k] ≤ 106
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code