The Middle Ground
A hard Python mock interview question on DataDriven. Practice with AI-powered feedback, real code execution, and a hire/no-hire decision.
- Domain
- Python
- Difficulty
- hard
- Seniority
- L5
Interview Prompt
Implement a RunningMedian class that supports add(num) and get_median(). get_median returns the current median of all values added so far (for an odd count, the exact middle value; for an even count, the average of the two middle values as a float). Then implement a driver run_operations(operations): it receives a list of operations where each operation is either ['add', x] or ['get_median']. Construct one RunningMedian, apply the operations in order, and return a parallel results list: append None for each 'add' and the returned median for each 'get_median'. Odd-count medians keep the value's original integer type; even-count medians are floats (e.g. 4.0). Values may be negative, zero, or duplicates.
Summary
The middle value keeps moving.
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