In Providence telemetry processing, an existing implementation checks every pair of event IDs to find the first duplicate, which is too slow for large inputs. Write an optimized algorithm that returns the index of the first event whose value has appeared earlier in the list.
Implement a function first_duplicate_event(events) where:
events, a list of integers representing event IDs in arrival order-1 if no duplicate existsA duplicate is any value that has already appeared earlier. “First duplicate” means the duplicate occurrence with the smallest index.
def first_duplicate_event(events):