Skip to content

ORIGINAL CODING QUESTION

First repeated application

Job application IDs arrive one at a time. Return the first ID that arrives for a second time, that is, the repeat occurring at the earliest position. Return -1 if every ID is different.

Open practice workspace

Original exercise · easy. Editorial role relevance does not imply a company has asked this question.

Input and output

First integer n, then n integers. Print one integer.

Constraints

1 ≤ n ≤ 200; 0 ≤ ID ≤ 1000.

Example 1

Input

6
3 8 5 8 3 9

Output

8

At position 3 the ID 8 repeats; the repeat of 3 comes later.

Example 2

Input

4
1 2 3 4

Output

-1

No ID repeats.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

The answer is decided the moment you meet an ID you have already seen.

Hint 2

Remember the IDs seen so far in a set.

Hint 3

Scan left to right; if the current ID is in the set return it, otherwise add it; return -1 after the loop.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →