#C12458. Find Duplicates in an Array
Find Duplicates in an Array
Find Duplicates in an Array
Given a sequence of integers, your task is to identify all duplicated numbers in the order they first appear as duplicates. Specifically, when an integer is encountered for the second (or subsequent) time, and it has not yet been listed as a duplicate, it should be added to the output list. If an integer appears more than twice, it should only be reported once, at the moment of its first repetition.
Input Format:
The first line contains an integer n denoting the number of integers in the sequence. The second line contains n space-separated integers.
Output Format:
Output the duplicated integers in a single line, separated by a single space. If there are no duplicates, output an empty line.
Example:
Input:
9 4 5 6 4 7 5 8 9 7
Output:
4 5 7
The solution must read from standard input (stdin) and write to standard output (stdout).
inputFormat
Format: The first line contains an integer n (0 ≤ n ≤ 105). The second line contains n integers separated by spaces.
Example:
9 4 5 6 4 7 5 8 9 7
outputFormat
Format: A single line containing the duplicated integers separated by a space. If there are no duplicates, output an empty line.
Example:
4 5 7## sample
9
4 5 6 4 7 5 8 9 7
4 5 7