Recover Both Unpaired Device IDs From a Pairing Handshake Log
Last updated: November 29, 2026
Quick Overview
In a Bluetooth pairing log for Ray-Ban Meta glasses, every device ID appears exactly twice except two IDs that appear once each. Return those two IDs in linear time and constant extra space.
Meta
November 29, 20260
0
0 solved
In a Bluetooth pairing log for Ray-Ban Meta glasses, every device ID appears exactly twice except two IDs that appear once each. Return those two IDs in linear time and constant extra space.
A Meta onsite coding question that builds on the single-XOR trick. The interviewer wants to see you reason that the XOR of the two answers is nonzero and use one differing bit to partition the input.
What the Interviewer Expects
- XOR everything to get a ^ b
- Argue that a ^ b has at least one set bit
- Isolate the lowest set bit with x & -x
- Partition by that bit and XOR each group
- Return both values in any order
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Why does x & -x isolate the lowest set bit?
- What if three IDs are unpaired?
- Can you do it if the log is spread over many shards?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of integers where exactly two distinct values appear once and every other value appears exactly twice. Output: the two singletons (any order). Constraints: O(n) time, O(1) extra space....
High-Level Design
XOR of everything gives x = a ^ b. Since a != b, x is nonzero, so some bit differs between a and b. Take the lowest such bit low = x & -x (two's complement negation flips all bits above the lowest...