You are migrating data from a DB to another datastore with a max acceptable lag of k seconds. Events are generated when data leaves the primary and when it reaches the secondary; build the verifier that raises an alert if data has not appeared in the secondary after k seconds.
Asked in the real-world problem round stage. Candidate did not remember wording exactly; related to the data migration team.
Implement verify_lag(events, k). events is a chronologically sorted list of [timestamp, event_type, record_id], where event_type is "leave" or "arrive". Each record has one leave event and at most one arrive event. Return record IDs whose arrival is later than k seconds after leaving or never occurs, ordered by alert time. Arrival exactly at the deadline is valid.
def verify_lag(events, k):