#C1461. Find the First Duplicate

    ID: 44278 Type: Default 1000ms 256MiB

Find the First Duplicate

Find the First Duplicate

Given a list of integers, your task is to find the first duplicate number in the list when reading from left to right. If no duplicate is found, output (-1).

More formally, you are given an array (a_1, a_2, \dots, a_n). Find the smallest index (i) such that there exists an index (j < i) with (a_i = a_j). If no such pair exists, output (-1).

inputFormat

The input is given through standard input as follows:

(n): an integer representing the number of elements in the list (first line).
(a_1, a_2, \dots, a_n): (n) space-separated integers provided on the second line.

outputFormat

Output a single integer representing the first duplicate found in the list. If there are no duplicates, output (-1).## sample

6
2 3 1 2 4 3
2