Problem 204
Find All Duplicates
Easy · 10 pts · Array, Hash Table
Problem
You are given an array of N integers. Print every value that appears more than once, in increasing order. Each repeated value is printed only once, however many times it appears. If no value repeats, print -1. Count the occurrences of each value with a hash map, then collect the values whose count is at least 2 and sort them.
Input
First line: integer N. Second line: N space-separated integers.
Output
Print the repeated values in increasing order, or -1.
Constraints
1 <= N <= 100000; -1000000000 <= A[i] <= 1000000000
Example input
8 4 3 2 7 8 2 3 1
Example output
2 3
Explanation
In 4 3 2 7 8 2 3 1, the values 2 and 3 each appear twice and every other value appears once. In increasing order the answer is 2 3.