#C9047. Find Missing and Duplicated Numbers
Find Missing and Duplicated Numbers
Find Missing and Duplicated Numbers
You are given an array of n integers. Each element is within the range \( [0, n-1] \). Some numbers may appear more than once (i.e. duplicates) and some numbers in the range might be missing. Your task is to:
- Sort the array in non-decreasing order.
- Identify the missing numbers from the set \( \{0, 1, 2, \dots, n-1\} \).
- Identify the numbers that appear more than once (duplicates).
The input is provided via standard input and the output must be printed to standard output. The output consists of three lines:
- The sorted array, with numbers separated by a space.
- The missing numbers in increasing order (if any), separated by a space.
- The duplicated numbers in increasing order (if any), separated by a space.
If there are no missing or duplicated numbers, output an empty line for that part.
inputFormat
The first line contains a single integer \( n \) indicating the number of elements in the array.
The second line contains \( n \) space-separated integers, representing the elements of the array.
outputFormat
Output exactly three lines:
- The first line contains the sorted array (elements separated by a space).
- The second line contains the missing numbers (separated by a space). If there are none, output an empty line.
- The third line contains the duplicated numbers (separated by a space). If there are none, output an empty line.
6
4 3 6 2 1 1
1 1 2 3 4 6
0 5
1
</p>