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.

Google
Coding & Algorithms
Data Scientist
Google
November 29, 2026
Data Scientist
Technical Screen
Coding & Algorithms
Medium

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
Sliding Window
Counting Substrings
Last Occurrence
Funnels
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
  • 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 Problems
Sample Answer
Requirements
  • Input: string s of a, 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...


Submit Your Answer
Markdown supported