Dsa
Bit Manipulation
Easy
The Triple-Bit Bridge
You are given a list of N unique integers. A 'Triple-Bit Bridge' exists between two numbers if their bitwise XOR result contains exactly 3 set bits. Count the total number of unique pairs (i, j) where i < j that form a Triple-Bit Bridge.
Example:
Input:
4
7 0 15 8
Output:
2
Explanation:
(7,0): 7^0 = 7 (binary 111, 3 bits) - YES.
(7,15): 7^15 = 8 (binary 1000, 1 bit) - NO.
(7,8): 7^8 = 15 (binary 1111, 4 bits) - NO.
(0,15): 0^15 = 15 (4 bits) - NO.
(0,8): 0^8 = 8 (1 bit) - NO.
(15,8): 15^8 = 7 (3 bits) - YES.
Total: 2.
Key concepts
bitwise_xorpopcountcounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now