Problem 484
Find the Repeating and Missing Numbers
Medium · 20 pts · Array, Math, Hash Table, Bit Manipulation
Problem
An array of N integers should contain every number from 1 to N exactly once, but one number was replaced by a copy of another. So one value appears twice and one value is missing. Find both. It can be solved in O(N) time and O(1) extra memory using the sum and the sum of squares of the values, or using XOR, but a counting array is also fine.
Input
First line: N. Second line: N integers.
Output
Print the repeating number and the missing number, separated by a space.
Constraints
2 <= N <= 100000; 1 <= A[i] <= N
Example input
3 3 1 3
Example output
3 2
Explanation
In 3 1 3, the value 3 appears twice and 2 never appears, so the answer is 3 2.