Find the Most Dissimilar Pair of Device Fingerprints by XOR
Last updated: November 29, 2026
Quick Overview
Device fingerprints are 32-bit integers, and the risk team wants the largest value of `a XOR b` over all pairs in a batch as a quick dissimilarity signal. Compute it faster than checking every pair.
TikTok
November 29, 20260
0
0 solved
Device fingerprints are 32-bit integers, and the risk team wants the largest value of `a XOR b` over all pairs in a batch as a quick dissimilarity signal. Compute it faster than checking every pair.
TikTok trust and safety teams cluster devices to spot fake account farms, and this question uses that framing to test bitwise reasoning. The interviewer expects you to move from O(n^2) to a binary trie that greedily picks the opposite bit from the most significant end, and to explain why greedy is correct there.
What the Interviewer Expects
- Starts with the O(n^2) baseline and states its cost for a million fingerprints
- Builds a binary trie over fixed-width bits, most significant first
- Explains why choosing the opposite bit greedily maximizes XOR
- Queries each value against previously inserted ones in one pass
- Verifies with a brute-force cross-check
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
- How would you answer queries of the form: max XOR of x with any fingerprint inserted so far?
- How would you support deleting fingerprints from the trie?
- What if you need the pair itself, not just the value?
- Is XOR a good dissimilarity measure for fingerprints? What would you use instead?
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 non-negative integers below 2^32. Output: maximum XOR over distinct index pairs, 0 if fewer than two values. n can be up to around 10^6, so O(n^2) at 10^12 operations is out....
High-Level Design
XOR is maximized by making the highest bits 1 first: a 1 at bit 31 beats any combination of lower bits, since 2^31 > 2^31 - 1. So for a value x, walking bits from most significant to least, we want a ...