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
You're correlating two time-sorted event streams where each event is a dict carrying a `timestamp` and a `value`, given a numeric `tolerance`. Walking `stream_a` in order, pair each event with the single nearest event in `stream_b` whose timestamp lies within `tolerance` of it, emitting a dict of `a_value`, `b_value`, and the absolute `gap`; an A event with nothing inside its window contributes no row. When two B events are equally near, keep the earlier one, and remember a single B event can be the nearest match for several A events.
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.