PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/CloudKitchens

Answer static and streaming Top-K queries

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of frequency counting, top-K selection, streaming and sliding-window algorithms and data-structure design in the Coding & Algorithms domain, testing both conceptual algorithmic reasoning and practical implementation skills.

  • medium
  • CloudKitchens
  • Coding & Algorithms
  • Software Engineer

Answer static and streaming Top-K queries

Company: CloudKitchens

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Top-K in static and streaming settings (3 variants) You are given integers and asked to answer **Top-K** queries under three different scenarios. ### Variant 1: Static Top-K Given an array `A` of `n` integers and an integer `k`, return the `k` most frequent values. - Input: `A` (length `n`), `k` - Output: list of `k` values (any order is acceptable unless you specify tie-breaking) - Clarify tie-breaking for equal frequencies (e.g., smaller value first, or any order). ### Variant 2: Real-time (unbounded) streaming Top-K You receive a stream of integers supporting operations: - `add(x)`: add one occurrence of value `x` - `topk()`: return the current `k` most frequent values Design an efficient data structure and implement these operations. ### Variant 3: Real-time Top-K within the last 1 hour (sliding window) Events arrive as `(timestamp, value)` where `timestamp` is in seconds (monotonic non-decreasing). Support: - `add(t, x)`: record event `x` at time `t` - `topk(t)`: return the `k` most frequent values considering only events with timestamps in `[t-3600, t]` ### Constraints to assume (unless you choose others) - `n` up to 2e5 for the static problem. - Streaming operations up to 2e5. - Values may repeat heavily. ### What to discuss - Time/space complexity tradeoffs for each variant. - How you maintain counts and retrieve Top-K efficiently, especially for the sliding window case. - Edge cases: fewer than `k` distinct values, ties, many unique values, bursts of events.

Quick Answer: This question evaluates understanding of frequency counting, top-K selection, streaming and sliding-window algorithms and data-structure design in the Coding & Algorithms domain, testing both conceptual algorithmic reasoning and practical implementation skills.

Related Interview Questions

  • Implement menu parser and serializer - CloudKitchens (medium)
  • Design a menu manager with enums - CloudKitchens (Medium)
  • Design an in-memory cloud storage system - CloudKitchens (Medium)
  • Design receipt system with combo discounts - CloudKitchens (Medium)
  • Implement concurrent order-accept/pickup simulator - CloudKitchens (medium)
CloudKitchens logo
CloudKitchens
Aug 20, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0

Top-K in static and streaming settings (3 variants)

You are given integers and asked to answer Top-K queries under three different scenarios.

Variant 1: Static Top-K

Given an array A of n integers and an integer k, return the k most frequent values.

  • Input: A (length n ), k
  • Output: list of k values (any order is acceptable unless you specify tie-breaking)
  • Clarify tie-breaking for equal frequencies (e.g., smaller value first, or any order).

Variant 2: Real-time (unbounded) streaming Top-K

You receive a stream of integers supporting operations:

  • add(x) : add one occurrence of value x
  • topk() : return the current k most frequent values

Design an efficient data structure and implement these operations.

Variant 3: Real-time Top-K within the last 1 hour (sliding window)

Events arrive as (timestamp, value) where timestamp is in seconds (monotonic non-decreasing). Support:

  • add(t, x) : record event x at time t
  • topk(t) : return the k most frequent values considering only events with timestamps in [t-3600, t]

Constraints to assume (unless you choose others)

  • n up to 2e5 for the static problem.
  • Streaming operations up to 2e5.
  • Values may repeat heavily.

What to discuss

  • Time/space complexity tradeoffs for each variant.
  • How you maintain counts and retrieve Top-K efficiently, especially for the sliding window case.
  • Edge cases: fewer than k distinct values, ties, many unique values, bursts of events.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More CloudKitchens•More Software Engineer•CloudKitchens Software Engineer•CloudKitchens Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.