ORIGINAL CODING QUESTION
Most distinct pair of feature masks
Each build is described by a nonnegative feature mask. For two different positions, their distinctness is the bitwise XOR of the two masks. Return the largest distinctness over all pairs.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
First integer n, then n integers. Print one integer.
Constraints
2 ≤ n ≤ 200; 0 ≤ mask ≤ 100,000.
Example 1
Input
4 6 9 12 3
Output
15
6 XOR 9 = 15, and no pair can exceed 15 because every mask is below 16.
Example 2
Input
3 7 7 7
Output
0
Equal masks have XOR 0.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Comparing all pairs is quadratic; a greedy over bits can do better.
Hint 2
A higher bit in the result is worth more than all lower bits combined, so decide bits from the most significant down.
Hint 3
Keep the best answer so far; for each bit, collect the masks truncated to the bits decided so far and test whether two prefixes XOR to the answer with this bit added.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →