#C10360. Find Duplicate Elements
Find Duplicate Elements
Find Duplicate Elements
You are given an array of integers. Your task is to find all the elements that appear more than once in the array and output them in the order of their first occurrence.
If an element appears at least twice, then the first time it appears is recorded as a duplicate when the element appears again. If no element appears more than once then the output should be an empty line.
The problem can be understood using the following formula: Let \(f(x)\) be the frequency of element \(x\) in the array. Then for each \(x\) such that \(f(x) > 1\), output \(x\) in the order that \(x\) makes its second (or subsequent) appearance for the first time.
inputFormat
The first line contains an integer \(n\) \( (0 \leq n \leq 10^5)\) representing the number of elements in the array.
The second line contains \(n\) space-separated integers.
outputFormat
Print the duplicate elements in a single line in the order in which they first appear as duplicates, separated by a single space. If there are no duplicates, print an empty line.
## sample7
1 2 3 4 4 5 2
4 2