3 ms·
This only works if you are simply missing one value, in this case the problem is presented that one number is missing and one is duplicated. (xor-all data) xor
by esrauch 16y ago
This only works if you are simply missing one value, in this case the problem is presented that one number is missing and one is duplicated.
(xor-all data) xor (xor-all Range-1-N) = missing# xor duplicate#
Simply knowing that last xor won't let you determine the actual values of missing# and duplicate# (just as the same thing with sum will end up giving you the difference between them and not their actual values).
- mikepurvis 16y agoInteresting you should say that. What about having both the sum and the xor? Then it's two equations, two unknowns. That should be enough to solve for it...
- esrauch 16y agoI actually posted a reply to this above, knowing both the sum and the xor is not sufficient to determine the two variables. Consider a situation where you know that (a xor b) = 1 and (a - b) = 1. Both a missing 2/extra 3 and missing 4/extra5 and any 2^N/2^N+1 are solutions to that equation. Just because you have two equations and two unknowns doesn't necessarily mean you end up with a single value for each except in certain circumstances (eg they are linear equations of full rank).