#K3171. Find All Duplicates in an Array
Find All Duplicates in an Array
Find All Duplicates in an Array
You are given an array of n integers where each integer is in the range \(1 \leq a_i \leq n\). Your task is to find all the duplicate numbers in the array without using extra space, aside from the output list. You may modify the array in-place.
If duplicates exist, print them in ascending order, separated by a single space. Otherwise, output -1
.
inputFormat
The first line contains a single integer n, the number of elements in the array. The second line contains n space-separated integers representing the array.
outputFormat
Output the duplicate numbers in increasing order, separated by a space. If there are no duplicates, output -1
.
8
4 3 2 7 8 2 3 1
2 3