Rolling Median Offer Price Over the Last K Seller Listings
Last updated: November 29, 2026
Quick Overview
Given the sequence of offer prices from sellers on one product listing and a window size k, return the median price of every window of k consecutive offers, used to detect outlier pricing.
Amazon
November 29, 20260
0
0 solved
Given the sequence of offer prices from sellers on one product listing and a window size k, return the median price of every window of k consecutive offers, used to detect outlier pricing.
An Amazon onsite hard problem tied to marketplace price monitoring, where a rolling median resists spikes better than a mean. The interviewer expects two heaps with lazy deletion, careful balancing, and a correct definition of the median for even k.
What the Interviewer Expects
- Keep a max-heap for the lower half and a min-heap for the upper half
- Remove outgoing values lazily with a pending-delete map
- Rebalance using logical sizes rather than heap lengths
- Define the even-k median as the mean of the two middle values
- State O(n log k) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would a balanced BST or sorted list change the code and complexity?
- What if you need the rolling 90th percentile instead of the median?
- How would you compute this per product across millions of listings in a stream processor?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list prices of numbers, window size 1 <= k <= n. Output: list of n - k + 1 medians. For odd k the middle value; for even k the average of the two middle values, as a float....
High-Level Design
lo is a max-heap (stored negated) holding the smaller half, hi a min-heap holding the larger half. Invariant on logical sizes: size_lo == size_hi or size_lo == size_hi + 1.
- Add x: p...