First Non-Repeating Tag in a Live Stream of Log Events

Last updated: November 29, 2026

Quick Overview

Design a class that receives tags one at a time via add(tag) and can return, at any moment, the earliest tag that has appeared exactly once so far (or None).

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Design a class that receives tags one at a time via add(tag) and can return, at any moment, the earliest tag that has appeared exactly once so far (or None).

A Google phone screen question that starts as the familiar first unique character problem and immediately shifts to a streaming constraint. The interviewer is checking whether you pick a data structure that makes both operations O(1) instead of rescanning history on every query.

What the Interviewer Expects
  • Recognizes that rescanning on each query is O(n) per call
  • Combines a count map with an insertion-ordered structure
  • Removes tags from the candidate set as soon as they repeat
  • Gives O(1) amortized add and first
  • Mentions memory growth for unbounded tag vocabularies
Key Topics to Cover
Hash Map
Ordered Dict
Streaming
Design
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if you only care about the last W events (a sliding window)?
  • How would you shard this across machines if tags arrive at millions per second?
  • Return the first k unique tags instead of one.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • add(tag): record one occurrence.
  • first(): return the earliest-added tag whose count is exactly 1, else None.
  • Both operations should be O(1) amortized; the stream is long and queries are freq...
High-Level Design

Keep two structures. A seen set records every tag ever observed. An OrderedDict named unique holds tags seen exactly once, in first-arrival order. On add: if the tag is new, put it in both; if i...


Submit Your Answer
Markdown supported