Drop events that arrive too late
Python data engineering interview problem. Difficulty: beginner. Pattern: Streaming. About 10 minutes. Free to practice.
Keep only the events that reached the system within an allowed delay of when they happened. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Each event is a pair (event_time, arrival_time), both in seconds. A stream job accepts an event only if it arrives soon enough after it happened. Implement drop_late(events, max_delay). Keep an event when arrival_time - event_time is at most max_delay. Return the kept events in their original order. Events with a delay of exactly max_delay are kept.
Requirements
- The original order is kept.
- A delay equal to max_delay is kept.
Constraints
- Arrival time is never earlier than event time.
- The input list is not changed.
Examples
Input: drop_late([(0, 5), (3, 9)], 5) Output: [(0, 5)] A delay of exactly 5 is kept. A delay of 6 is dropped.
Topics: lakebench, python, stream, late data, watermark, event.
More Python interview questions · All interview problems · Learn data engineering
Drop events that arrive too late
Interview-style drill: Keep only the events that reached the system within an allowed delay of when they happened.
Each event is a pair `(event_time, arrival_time)`, both in seconds. A stream job accepts an event only if it arrives soon enough after it happened. Implement `drop_late(events, max_delay)`. - Keep an event when `arrival_time - event_time` is at most `max_delay`. - Return the kept events in their original order. - Events with a delay of exactly `max_delay` are kept.