Split an Event Stream Into the Fewest Segments With No Repeats

Last updated: November 29, 2026

Quick Overview

A Firebase Analytics session is a string where each letter is an event type. Split it into contiguous segments such that no event type appears twice within one segment, using as few segments as possible, and return the count.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


A Firebase Analytics session is a string where each letter is an event type. Split it into contiguous segments such that no event type appears twice within one segment, using as few segments as possible, and return the count.

An easy greedy that shows up in Google online assessments: extend each segment as long as possible. The interviewer checks that you reset correctly and can explain why cutting late is never worse than cutting early.

What the Interviewer Expects
  • Grow the current segment until a repeat appears
  • Start a new segment at the repeating character
  • Use a set or bitmask of seen letters
  • Justify why the longest possible first segment is optimal
  • O(n) time
Key Topics to Cover
Greedy
Hash set
Bitmask
Strings
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
  • Return the segments themselves.
  • Each event type may appear at most twice per segment.
  • Minimize segments when each segment can hold at most k distinct event types.
  • Process the stream online with O(1) memory per segment.
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

Input: lowercase string s. Output: the minimum number of contiguous segments, each with all distinct characters. Empty string needs 0 segments....

High-Level Design

Scan once with the set of characters in the current segment. When the next character is already in the set, close the segment, start a new one containing just that character, and count it.

Optimality...


Submit Your Answer
Markdown supported