#K50312. Find the First Duplicate Integer
Find the First Duplicate Integer
Find the First Duplicate Integer
Given an array of integers, your task is to find the first duplicate element when traversing the array from left to right. If there is no duplicate, output -1.
More formally, given an array , you need to find the smallest index such that there exists a with and . If no such index exists, print -1.
inputFormat
The first line of input contains an integer — the number of elements in the array. The second line contains space-separated integers, representing the array.
outputFormat
Output a single integer: the first duplicate encountered while traversing the array from left to right. If there is no duplicate, output -1.## sample
7
1 2 3 4 2 5 6
2