A load-testing tool hashes pairs of session ids with XOR (^) and wants the pair that differs the most. a ^ b sets a bit to 1 wherever a and b have different bits.
Write largestXor(ids) that returns the largest value of ids[i] ^ ids[j] over all positions i and j. If there is only one id, return 0. Aim for better than checking every pair.
Input: ids = [3,10,5,25,2,8] Output: 28
5 ^ 25 is 00101 ^ 11001 = 11100, which is 28.
Input: ids = [7] Output: 0
With one id, the only pair is the id with itself.
1 <= ids.length <= 2 * 10^40 <= ids[i] < 2^31Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #372 Largest XOR of Two Session IDs. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.