CJCoding With Joseph
15free / daySign inCreate account

First Repeated Value

Write first_duplicate(values: list[int]) -> int that returns the first value whose second appearance is reached while walking the list from left to right, or -1 when nothing repeats. For 3 1 4 1 5 3 the answer is 1, because the second 1 comes before the second 3. Keep a set of the values seen so far and use its add() method. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of space-separated integers (possibly empty); the tests print the value your function returns.

Expected Output:

1

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
Data Structures & Algorithms
📥 Auto-Input:
3 1 4 1 5 3\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.