#K91352. Find the First Duplicate in a List
Find the First Duplicate in a List
Find the First Duplicate in a List
You are given an integer \( n \) and a list of \( n \) integers. Your task is to determine if there is any duplicate in the list. If duplicates exist, output YES
followed by the first duplicate number encountered in the list. Otherwise, output NO
.
For example, if the list is [1,2,3,2,4,5], the output should be YES 2
because 2 is the first number that appears more than once.
Please read input from standard input (stdin) and write your output to standard output (stdout).
inputFormat
The first line contains an integer \( n \) (the number of elements in the list). The second line contains \( n \) integers separated by spaces.
Example:
6 1 2 3 2 4 5
outputFormat
If a duplicate is found, output YES
followed by a space and the first duplicate number. If no duplicates are found, output NO
.
Example outputs:
NO YES 2## sample
5
1 2 3 4 5
NO
</p>