Not sure what to study next?

Get a personalised quant interview roadmap built around your upcoming interviews, strengths and weaknesses.

Takes a few minutes. Start with your target role and firms.

← Programming questions
Hard / PYTHON

Running Median at Requested Checkpoints

heaps · streaming · order_statistics 38 minute study target

Not completed

Challenge

Values arrive one at a time. For each requested prefix length k, return the median of values[:k]. For odd k, use the middle sorted value; for even k, average the two middle values. Output medians in checkpoint order. Do not sort every queried prefix afresh.

Input and output contract

0 ≤ n ≤ 60,000; |value| ≤ 1,000,000; checkpoints is a strictly increasing list of at most 1,500 integers in 1..n. An empty checkpoint list returns []. Numeric answers use 1e-7 absolute or 1e-9 relative tolerance. Only requested checkpoints produce output, keeping results within the runner’s output budget.

All tests follow this contract. You do not need to validate malformed input. Return the requested result from running_median; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.

Target complexity: O(n log(n + 1)) time; O(n) auxiliary space

Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.

Public examples

Example 1

Arguments

[[5, 1, 9, 3], [1, 2, 4]]

Expected return

[5.0, 3.0, 4.0]
Example 2

Arguments

[[-3, -1], [2]]

Expected return

[-2.0]
Example 3

Arguments

[[], []]

Expected return

[]
Hint

Maintain a max-heap of the lower half and a min-heap of the upper half. Their sizes differ by at most one.

The worked solution unlocks after completion, or with Premium access.

running_median.pyPython 3.12

Drafts are saved to your account, not to shared browser storage.

Sign in to submit code and save progress.

Results

Your results will appear here.

Hidden tests reveal only their pass/fail status, never their inputs or expected outputs. Runtime is observed wall time—not an inferred complexity class.

Join our Newsletter and Receive the Latest Updates!

Main Links

Trade Courses Assessments Interview Prep Contact Us

Social Media

Facebook Instagram YouTube

Legal

Terms and Conditions Privacy Policy Privacy settings

Talent Acquisition

Looking to hire exceptional quant talent?
See how we can help.

© 2026 EverythingQuant. All Rights Reserved.