The Stream Joiner
A hard Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- hard
- Seniority
- L5
Problem
Given two sorted lists of event dicts (each with 'timestamp' and 'value') and a numeric tolerance, for each event in stream_a find the nearest event in stream_b whose |timestamp_a - timestamp_b| <= tolerance. If such a match exists, append a dict with keys 'a_value' (the A event's value), 'b_value' (the matched B event's value), and 'gap' (the absolute time difference, a float). Events with no B event inside the tolerance window are skipped. Return the list of match dicts in input-order of stream_a. If multiple stream_b events tie for nearest, choose the earliest. A single B event may match multiple A events (B events are never consumed).
Summary
Events don't wait for each other. This does.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.