PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Google

Find top/bottom-k words in list or stream

Last updated: May 13, 2026

Quick Overview

This question evaluates skills in frequency counting, top-k and bottom-k selection, streaming algorithms, and data-structure design for maintaining order, tie-breaking, and dynamic updates.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Find top/bottom-k words in list or stream

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given words (strings) either as a finite list or as an unbounded stream. 1) **List version**: Given an array `words` and an integer `k`, return: - the `k` most frequent distinct words, and - the `k` least frequent distinct words. Specify how you break ties (e.g., lexicographically, or any order). 2) **Stream version (online)**: Design a data structure that supports: - `ingest(word)`: process the next word in the stream - `topK(k)`: return the `k` most frequent distinct words seen so far - `bottomK(k)`: return the `k` least frequent distinct words seen so far Discuss time/space complexity and how you would implement these operations efficiently. 3) **Variant (discuss/design)**: Extend the stream design to support returning the **first `k`** and/or **last `k`** words that are currently **non-repeating** (i.e., words with frequency exactly 1) according to stream arrival order.

Quick Answer: This question evaluates skills in frequency counting, top-k and bottom-k selection, streaming algorithms, and data-structure design for maintaining order, tie-breaking, and dynamic updates.

Related Interview Questions

  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Solve Shortest Paths and Rental Allocation - Google (medium)
  • Solve Two Array Optimization Problems - Google (medium)
Google logo
Google
Jan 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0

You are given words (strings) either as a finite list or as an unbounded stream.

  1. List version : Given an array words and an integer k , return:
  • the k most frequent distinct words, and
  • the k least frequent distinct words.

Specify how you break ties (e.g., lexicographically, or any order).

  1. Stream version (online) : Design a data structure that supports:
  • ingest(word) : process the next word in the stream
  • topK(k) : return the k most frequent distinct words seen so far
  • bottomK(k) : return the k least frequent distinct words seen so far

Discuss time/space complexity and how you would implement these operations efficiently.

  1. Variant (discuss/design) : Extend the stream design to support returning the first k and/or last k words that are currently non-repeating (i.e., words with frequency exactly 1) according to stream arrival order.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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

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