Problem 809
Find All Numbers Disappeared in an Array
Easy · 10 pts · Array, Hash Table
Problem
An array of N integers contains only values from 1 to N, but some values may appear more than once, which means others are missing. Print every value from 1 to N that does not appear in the array, in increasing order, or NONE if nothing is missing. A boolean 'seen' array works; to use O(1) extra space, mark value v as seen by making A[v - 1] negative.
Input
The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1]. Every value is between 1 and N.
Output
Print the missing values in increasing order separated by spaces, or NONE.
Constraints
1 <= N <= 100000; 1 <= A[i] <= N
Example input
8 4 3 2 7 8 2 3 1
Example output
5 6
Explanation
In 4 3 2 7 8 2 3 1 (N = 8), the values 5 and 6 never appear, so the answer is 5 6.