Track Rolling 90-Day Median Sale Price for Every ZIP Code

Last updated: November 29, 2026

Quick Overview

Closed sales stream in by day as (zip, day, price). Support record_sale and median(zip, today), where the median covers only sales in that ZIP from the last 90 days, with both operations in logarithmic amortized time.

Zillow
Coding & Algorithms
Software Engineer
Zillow
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Closed sales stream in by day as (zip, day, price). Support record_sale and median(zip, today), where the median covers only sales in that ZIP from the last 90 days, with both operations in logarithmic amortized time.

Local market stats such as the median sale price on Zillow's market pages and inputs to home value indexes are rolling-window aggregates over a sales feed. This onsite question checks whether you know the two-heap median, can add deletion through lazy invalidation, and keep per-key state tidy.

What the Interviewer Expects
  • Explain why a sorted list gives O(n) inserts and why two heaps do better
  • Keep the low max-heap and high min-heap balanced with live counts, not heap lengths
  • Delete expired sales lazily with a dead set and prune at the heap tops
  • Expire by a per-ZIP queue, since sales arrive in time order
  • Verify against a brute-force median on random data
Key Topics to Cover
two heaps
lazy deletion
sliding window
streaming statistics
hash map of structures
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Sales can arrive late, up to a week out of order. What changes?
  • How would you serve the 25th and 75th percentiles as well?
  • Memory is tight across 40,000 ZIPs. Would an approximate sketch be acceptable, and which one?
  • How would you shard this across machines?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Days are integers, non-decreasing across calls. A sale on day d is in the window for today when d > today - 90. Prices can repeat, so each sale gets a unique id. median returns None for a ZIP wi...

High-Level Design

Per ZIP keep (1) a deque of (day, sale_id) in arrival order for expiry and (2) a two-heap median structure. The low heap holds the smaller half as a max-heap, the high heap the larger half; invarian...


Submit Your Answer
Markdown supported

Related Questions