PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Google

Detect and remove matched words in a char stream

Last updated: May 12, 2026

Quick Overview

This question evaluates understanding of online stream processing, substring matching, and the use of efficient data structures and algorithms for real-time updates and deletions.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Detect and remove matched words in a char stream

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are processing a stream of characters (arriving one-by-one). You are also given a list of target words. Each time a new character arrives, it is appended to the end of the current stream buffer. After appending, if the buffer contains **any** target word as a **contiguous substring**, you must: 1. **Return/report** a matched word (assume if multiple words match, you may return any one of them, but you must define and follow a consistent rule such as “return the first match found” or “return the longest match”). 2. **Delete** that occurrence of the matched word from the buffer (remove exactly those characters), then continue processing future characters. ### Clarifications to make explicit in your solution - Can matches overlap? If multiple matches exist simultaneously, which one do you remove? - Do you remove only one word per incoming character, or repeatedly remove until no word remains? ### Input/Output (one reasonable interface) - Input: `words: List[str]`, and a sequence of calls `query(c: char)`. - Output per call: the matched word (or empty string / null if no match). The internal buffer should reflect deletions. ### Constraints (typical interview-scale) - Number of words: up to ~10^4 - Total length of all words: up to ~10^5 - Stream length can be large (online processing required).

Quick Answer: This question evaluates understanding of online stream processing, substring matching, and the use of efficient data structures and algorithms for real-time updates and deletions.

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
Feb 7, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
30
0
Loading...

You are processing a stream of characters (arriving one-by-one). You are also given a list of target words.

Each time a new character arrives, it is appended to the end of the current stream buffer. After appending, if the buffer contains any target word as a contiguous substring, you must:

  1. Return/report a matched word (assume if multiple words match, you may return any one of them, but you must define and follow a consistent rule such as “return the first match found” or “return the longest match”).
  2. Delete that occurrence of the matched word from the buffer (remove exactly those characters), then continue processing future characters.

Clarifications to make explicit in your solution

  • Can matches overlap? If multiple matches exist simultaneously, which one do you remove?
  • Do you remove only one word per incoming character, or repeatedly remove until no word remains?

Input/Output (one reasonable interface)

  • Input: words: List[str] , and a sequence of calls query(c: char) .
  • Output per call: the matched word (or empty string / null if no match). The internal buffer should reflect deletions.

Constraints (typical interview-scale)

  • Number of words: up to ~10^4
  • Total length of all words: up to ~10^5
  • Stream length can be large (online processing required).

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.