PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/Microsoft

Design top-K frequency store for varying workloads

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of data structures, algorithmic complexity, and workload-driven design trade-offs for maintaining frequency counts and computing top-K results in an online stream.

  • medium
  • Microsoft
  • Software Engineering Fundamentals
  • Software Engineer

Design top-K frequency store for varying workloads

Company: Microsoft

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Onsite

### Scenario You need to design an in-memory component that tracks how often each key appears in a stream of events. The component must support these operations: - `record(key)`: increment the count for `key` by 1 (insert `key` if not present). - `topK(k)`: return the `k` keys with the highest counts so far (order among them does not matter). Assume: - There can be up to `N` distinct keys. - Operations happen online as the stream arrives. ### Task Describe how you would implement this component under two different workload patterns: 1. **Read-heavy**: there are many more `topK(k)` calls than `record(key)` calls. 2. **Write-heavy**: there are many more `record(key)` calls than `topK(k)` calls. For each case, specify: - The main data structures you would use. - Time complexity of `record` and `topK`. - Space complexity. - Why your design is appropriate for that workload (the trade-offs you’re making).

Quick Answer: This question evaluates understanding of data structures, algorithmic complexity, and workload-driven design trade-offs for maintaining frequency counts and computing top-K results in an online stream.

Related Interview Questions

  • Explain OOP design and API rollout - Microsoft (hard)
  • Explain a project deeply - Microsoft (medium)
  • Explain Python, Java, and Memory Management - Microsoft (medium)
  • Explain how browser authentication works with JWTs - Microsoft (hard)
  • Compute precision/recall from a flaky top-k API - Microsoft (medium)
Microsoft logo
Microsoft
Nov 3, 2025, 12:00 AM
Software Engineer
Onsite
Software Engineering Fundamentals
2
0

Scenario

You need to design an in-memory component that tracks how often each key appears in a stream of events.

The component must support these operations:

  • record(key) : increment the count for key by 1 (insert key if not present).
  • topK(k) : return the k keys with the highest counts so far (order among them does not matter).

Assume:

  • There can be up to N distinct keys.
  • Operations happen online as the stream arrives.

Task

Describe how you would implement this component under two different workload patterns:

  1. Read-heavy : there are many more topK(k) calls than record(key) calls.
  2. Write-heavy : there are many more record(key) calls than topK(k) calls.

For each case, specify:

  • The main data structures you would use.
  • Time complexity of record and topK .
  • Space complexity.
  • Why your design is appropriate for that workload (the trade-offs you’re making).

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More Microsoft•More Software Engineer•Microsoft Software Engineer•Microsoft Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals
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.