← Problem library

Arrays · Python

First Duplicate

HardArraysUnsolved

Problem

Return the first duplicate value encountered from left to right, or -1 if none exists.

Example input

nums = [2, 1, 3, 5, 3, 2]

Example output

3

Constraints

1 <= len(nums) <= 100,000

Python workspace

Reset code

Execution uses a timed child process in a temporary directory. It is development-only isolation, not a production sandbox.