The Stream Averager
A easy Python mock interview question on DataDriven. Practice with AI-powered feedback, real code execution, and a hire/no-hire decision.
- Domain
- Python
- Difficulty
- easy
- Seniority
- L5
Interview Prompt
Implement the StreamAverager class with add(key, value) and get_averages(). add(key, value) records one numeric reading for key. get_averages() returns a dict mapping each key seen so far to the average (mean) of its values; before any reading is added it returns an empty dict {}. A driver run_stream_averager(operations) is provided: operations is a list where each entry is either ['add', key, value] or ['get_averages']. Create a single StreamAverager, apply the operations in order on it, and return a parallel list of results: None for each 'add' and the dict for each 'get_averages'. Averages are floats (e.g. add('sensor_a', 10), add('sensor_a', 30), get_averages() -> {'sensor_a': 20.0}).
Summary
The answer moves with the data.
How This Interview Works
- Read the vague prompt (just like a real interview)
- Ask clarifying questions to the AI interviewer
- Write your python solution with real code execution
- Get instant feedback and a hire/no-hire decision