Andres,

You don't need bitmasks - you just need xor.

Step by step, algorithm, which solves both small and large in milliseconds:

- take first number from first group.
- xor it with all numbers from second group. You'll get at most 50 numbers. 
These 50 numbers are the only numbers you need to check.
- for each of these 50 numbers you need to do the following:
   - xor all numbers from first list with this number (at most 50 xors)
   - check if both lists contain the same numbers - you can sort and check or 
use some "set" data structure. If they match, then your number is valid option. 
Save it.

- for each valid number (you'll get just a few of them) you need to count 
numbers of bit set. And take the smallest number.

In Python the whole solution is less then 10 lines of code.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/ce548c84-610f-4839-8c64-0fe0da924863%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to