Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Optimize Duplicate Event Detection

Medium
MediumCodingHash TablesArraysSortingAsked 1 times

Problem

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.

Formal Specification

Implement a function first_duplicate_event(events) where:

  • Input: events, a list of integers representing event IDs in arrival order
  • Output: the index of the first duplicate event occurrence, or -1 if no duplicate exists

A duplicate is any value that has already appeared earlier. “First duplicate” means the duplicate occurrence with the smallest index.

Constraints

  • 1 <= len(events) <= 10^5
  • -10^9 <= events[i] <= 10^9
  • Input contains integers only
  • Return the index of the earliest duplicate occurrence, or -1 if none exists

Function Signature

def first_duplicate_event(events):
Practicing as: Engineering Manager interview at Providence

Hi, I'll play your Providence interviewer for the Engineering Manager role. Answer the question above like we're in the room, and I'll respond the way a real interviewer would.

Take this as a live interview session →

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
def solve(rows):
    counts = {}
    for row in rows:
        ...
    return result
Sign up to unlock solutions
Providence Engineering Manager Interview QuestionsProvidence Interview Questions
Next questions
Alten NederlandFind Duplicate Event IDEasyKlaviyoDeduplicate Events Preserving First OrderEasyMetaDeduplicate Ordered Event StreamMedium