PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Count super-streak segments in an event stream

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in processing time-ordered event streams, reasoning about temporal segmentation and constraints, and applying algorithmic techniques to count maximal contiguous segments that satisfy type, gap, count, and duration criteria.

  • easy
  • Google
  • Coding & Algorithms
  • Data Scientist

Count super-streak segments in an event stream

Company: Google

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem You are given a time-ordered sequence of events. Each event has: - `type` (string or int) - `ts` (timestamp as integer milliseconds/seconds) A **streak segment** is a **maximal contiguous subsequence** of the input where: 1. All events have the same `type`, and 2. For every pair of adjacent events in the segment, the time gap is within a threshold: \(ts[i] - ts[i-1] \le T\). A streak segment is a **super streak** if it satisfies **all** of the following: - **Count condition:** number of events in the segment \(\ge N\) - **Gap condition:** already enforced by the segment definition (all adjacent gaps \(\le T\)) - **Duration condition:** total duration of the segment \(= ts[last] - ts[first] \ge X\) - Note: a segment with a single event has duration 0. ### Task Implement a function that returns the **number of super streak segments** in the sequence. ### Assumptions / clarifications - Input events are sorted by `ts` ascending. - `T`, `N`, and `X` are given as non-negative values. - Use inclusive gap threshold: a gap exactly equal to `T` is allowed. ### Example (informal) If a segment has 5 events of the same type, all adjacent gaps \(\le T\), and spans from time 10 to 25, then it is a super streak iff \(5 \ge N\) and \(25-10 \ge X\). ### Follow-up How would you adapt your solution if parameters `N`, `T`, and/or `X` can **change over time** (e.g., different thresholds apply to different portions of the event sequence)?

Quick Answer: This question evaluates proficiency in processing time-ordered event streams, reasoning about temporal segmentation and constraints, and applying algorithmic techniques to count maximal contiguous segments that satisfy type, gap, count, and duration criteria.

Related Interview Questions

  • Solve Rooms and Top-K Streams - Google (medium)
  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Implement Employee Management and Expression Evaluation - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)
Google logo
Google
Jan 2, 2025, 12:00 AM
Data Scientist
Technical Screen
Coding & Algorithms
10
0

Problem

You are given a time-ordered sequence of events. Each event has:

  • type (string or int)
  • ts (timestamp as integer milliseconds/seconds)

A streak segment is a maximal contiguous subsequence of the input where:

  1. All events have the same type , and
  2. For every pair of adjacent events in the segment, the time gap is within a threshold:
    ts[i]−ts[i−1]≤Tts[i] - ts[i-1] \le Tts[i]−ts[i−1]≤T .

A streak segment is a super streak if it satisfies all of the following:

  • Count condition: number of events in the segment ≥N\ge N≥N
  • Gap condition: already enforced by the segment definition (all adjacent gaps ≤T\le T≤T )
  • Duration condition: total duration of the segment =ts[last]−ts[first]≥X= ts[last] - ts[first] \ge X=ts[last]−ts[first]≥X
    • Note: a segment with a single event has duration 0.

Task

Implement a function that returns the number of super streak segments in the sequence.

Assumptions / clarifications

  • Input events are sorted by ts ascending.
  • T , N , and X are given as non-negative values.
  • Use inclusive gap threshold: a gap exactly equal to T is allowed.

Example (informal)

If a segment has 5 events of the same type, all adjacent gaps ≤T\le T≤T, and spans from time 10 to 25, then it is a super streak iff 5≥N5 \ge N5≥N and 25−10≥X25-10 \ge X25−10≥X.

Follow-up

How would you adapt your solution if parameters N, T, and/or X can change over time (e.g., different thresholds apply to different portions of the event sequence)?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Data Scientist•Google Data Scientist•Google Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.