Rolling Median Loan Amount Over the Last W Applications
Last updated: November 29, 2026
Quick Overview
Given a stream of requested loan amounts, return the median of every window of the last w applications. The solution must be faster than sorting each window.
Upstart
November 29, 20260
0
0 solved
Given a stream of requested loan amounts, return the median of every window of the last w applications. The solution must be faster than sorting each window.
Upstart monitors funnel drift, and a rolling median of requested amounts is a robust signal when an affiliate partner starts sending a different population. The onsite version tests two-heap median maintenance plus removal of expired elements, which is where most candidates struggle.
What the Interviewer Expects
- Maintain a max-heap for the lower half and a min-heap for the upper half
- Support removal with lazy deletion
- Track logical heap sizes separately from physical sizes
- Rebalance so the lower half has the extra element
- Verify against a brute force
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
- What if amounts fall in a small integer range? Can a counting structure beat heaps?
- How would you return a rolling 90th percentile instead?
- How would you compute this approximately across millions of events per minute?
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 of numbers and window size w with 1 <= w <= n. Output: n - w + 1 medians as floats; even windows average the two middle values....
High-Level Design
Two heaps split the window: low holds the smaller half as a max-heap, high the larger half. The median is the top of low (odd w) or the average of both tops. Heaps cannot delete arbitrary items,...