Problem
In an Alten Nederland mobile app telemetry pipeline, event IDs should be unique within a single upload batch. Given a list of integers event_ids, return the first value that appears more than once when scanning from left to right. If no duplicate exists, return -1.
Formal Specification
- Input:
event_ids, a list of integers - Output: An integer representing the first duplicated value encountered during a left-to-right scan, or
-1if all values are unique
A value is considered the first duplicate if its second occurrence appears before the second occurrence of any other duplicated value.
Constraints
- 1 <= len(event_ids) <= 10^5
- -10^9 <= event_ids[i] <= 10^9
- Return the value whose second occurrence appears first
- If no duplicate exists, return -1
Function Signature
def first_duplicate(event_ids):
Practicing as: Mobile Engineer interview at Alten NederlandHi, I'll play your Alten Nederland interviewer for the Mobile Engineer role. Answer the question above like we're in the room, and I'll respond the way a real interviewer would.
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

