One id duplicated, one missing, find both
A settlement batch should contain every id from to exactly once. Because of a bug, one id got written twice and, as a result, a different id is entirely missing. The array still has length .
ids = [1, 2, 2, 4] # range is 1..4: id 2 is duplicated, id 3 is missing
-> (2, 3) # (duplicated, missing)
Return the duplicated id and the missing id in time and space.
Show a hint
XOR the array against the full range . You get dup XOR missing. How do you split two survivors apart?
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.