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.
event_ids, a list of integers-1 if all values are uniqueA value is considered the first duplicate if its second occurrence appears before the second occurrence of any other duplicated value.
Example 1
event_ids = [4, 7, 1, 7, 3, 1]77 is the first value whose second occurrence is encountered.Example 2
event_ids = [2, 5, 6, 8]-11 <= len(event_ids) <= 10^5-10^9 <= event_ids[i] <= 10^9After implementing the function, discuss the time complexity of your solution and why it is better than checking every pair.
event_ids = [4, 7, 1, 7, 3, 1]Output7WhyThe second occurrence of `7` appears before the second occurrence of `1`, so `7` is the first duplicate.event_ids = [2, 5, 6, 8]Output-1WhyAll values are unique, so there is no duplicate to return.event_ids = [9, 9, 2, 2]Output9WhyThe duplicate `9` is found immediately at index 1, before any other duplicate can occur.1 <= len(event_ids) <= 10^5-10^9 <= event_ids[i] <= 10^9Return the value whose second occurrence appears firstIf no duplicate exists, return -1def first_duplicate(event_ids):