Count Log Segments Containing All Three Event Types
Last updated: November 29, 2026
Quick Overview
A string over the letters 'a', 'b' and 'c' records click, view and purchase events. Count the substrings that contain at least one of each event type.
0
0
0 solved
A string over the letters 'a', 'b' and 'c' records click, view and purchase events. Count the substrings that contain at least one of each event type.
A Google technical-screen counting window, framed around funnel analysis where a session counts only if it contains all three steps. The interviewer checks the at-least counting trick: once a window is valid, every extension to the right is also valid.
What the Interviewer Expects
- Recognizes the at-least-one-of-each monotonicity
- Counts by left edge or by last-seen positions
- Avoids O(n^2) enumeration
- Handles strings missing a letter
- States 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
- Generalize to k event types.
- Count substrings with exactly one purchase and at least one click.
- What if the log has millions of sessions processed in parallel?
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: string
sofa,b,c. - Output: number of substrings (by position) containing all three letters....
High-Level Design
Fix the right end at index i. A substring s[j..i] contains all three letters exactly when j is at or before the earliest of the three most recent positions of a, b and c. So if last hold...