← Zillow Interview Insights

Zillow·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Interviewed for an MLE role at Zillow and got a coding question centered on streaming data and maintaining order statistics efficiently. Pretty standard for this kind of role but the design angle made it slightly more interesting than a pure leetcode grind.

Questions Asked (1)

Q1

Design a class that takes an integer k and an initial list of numbers, and supports an add(val) method that inserts a new value into the stream and returns the k-th largest element seen so far.

Algorithms & Data StructuresSystem Design
Author's notes

The heap angle is pretty obvious once you think about it for a minute, keep a min-heap of size k and the top is always your answer.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: k is fixed, and we need to support add and query k-th largest efficiently. Then propose a min-heap of size k to maintain the k largest elements, where the root is the k-th largest. Discuss time and space complexity, and handle edge cases like k > number of elements.

Pro tip: Mention that if k is large or the stream is unbounded, a balanced BST or order-statistic tree could be used, but a heap is optimal for typical k. Also, note that if k can change, the design would differ.

1. Clarify requirements and constraints

Ask if k is fixed, if the initial list can be empty, and what should be returned if fewer than k elements have been seen. Confirm that add returns the k-th largest after insertion.

2. Choose data structure

Propose a min-heap of size k to store the k largest elements seen so far. The root of the heap is the k-th largest element.

3. Design add method

For each new value, if heap size < k, push it; else if value > heap root, pop root and push value. Then return heap root if size == k, else indicate not enough elements.

4. Analyze complexity

Explain that each add takes O(log k) time and O(k) space. Initialization from list takes O(n log k) if done naively, but can be optimized to O(n) using heapify if we only need k largest.

5. Discuss edge cases and alternatives

Handle k=1 (max element), k larger than stream size, and duplicate values. Mention alternatives like quickselect for static data or balanced BST for dynamic k.

Key Points to Mention

  • Min-heap of size k maintains the k largest elements, with root as k-th largest.
  • Time complexity: O(log k) per add, O(k) space.
  • Initialization: can use heapify on first k elements, then process rest.
  • Edge cases: k <= 0, k > number of elements seen, duplicates.
  • Alternative: use a max-heap of size n-k+1? No, min-heap is standard.
  • If k is very large, consider a balanced BST or order-statistic tree.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.