PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Zillow

Implement k-th largest in a number stream

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency with data structures and order-statistics in a streaming context, focusing on API design and time/space complexity trade-offs within the Coding & Algorithms domain.

  • medium
  • Zillow
  • Coding & Algorithms
  • Machine Learning Engineer

Implement k-th largest in a number stream

Company: Zillow

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are designing a small library to monitor statistics over a stream of integers. Implement a data structure that, given an integer `k` and an initial list of integers, supports the following operation: - `add(val)`: insert the integer `val` into the stream and return the **k-th largest** element among all elements seen so far (including the new one). More formally, after each call to `add`, if you took all numbers that have been provided (both the initial list and all numbers added so far), sorted them in **non-decreasing** order, you should return the element that is `k` positions from the end (the k-th largest). You may assume that `k` is always valid (i.e., there are at least `k` elements after each `add` call). ### API to implement Define a class or type with: - A constructor that takes: - `k` (an integer) - `nums` (a list/array of integers, possibly empty) - A method: - `add(val: int) -> int` that inserts `val` and returns the current k-th largest element. ### Constraints - You may assume: - `1 \le k \le 10^4` - At most `10^4` calls to `add` will be made. - Each integer value fits in a standard 32-bit signed integer. - Your design should be efficient enough to handle the worst-case number of `add` calls within typical interview time complexity expectations. Describe only the code-level behavior and interface; you do **not** need to provide a working implementation here.

Quick Answer: This question evaluates proficiency with data structures and order-statistics in a streaming context, focusing on API design and time/space complexity trade-offs within the Coding & Algorithms domain.

Related Interview Questions

  • Write pseudocode for a ReAct-style loop - Zillow (medium)
  • Find max min-plus-max over all subarrays - Zillow (medium)
  • Implement placeholder-based pattern matcher - Zillow (medium)
Zillow logo
Zillow
Sep 24, 2025, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
1
0

You are designing a small library to monitor statistics over a stream of integers.

Implement a data structure that, given an integer k and an initial list of integers, supports the following operation:

  • add(val) : insert the integer val into the stream and return the k-th largest element among all elements seen so far (including the new one).

More formally, after each call to add, if you took all numbers that have been provided (both the initial list and all numbers added so far), sorted them in non-decreasing order, you should return the element that is k positions from the end (the k-th largest). You may assume that k is always valid (i.e., there are at least k elements after each add call).

API to implement

Define a class or type with:

  • A constructor that takes:
    • k (an integer)
    • nums (a list/array of integers, possibly empty)
  • A method:
    • add(val: int) -> int that inserts val and returns the current k-th largest element.

Constraints

  • You may assume:
    • 1 \le k \le 10^4
    • At most 10^4 calls to add will be made.
    • Each integer value fits in a standard 32-bit signed integer.
  • Your design should be efficient enough to handle the worst-case number of add calls within typical interview time complexity expectations.

Describe only the code-level behavior and interface; you do not need to provide a working implementation here.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Zillow•More Machine Learning Engineer•Zillow Machine Learning Engineer•Zillow Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.