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.
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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...