PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Gemini

Detect k events in a sliding window

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to design efficient sliding-window and streaming algorithms for time-series event data, encompassing deduplication, handling bounded out-of-order arrivals and clock skew, distinct-device counting, and meeting specified time and space complexity constraints.

  • Medium
  • Gemini
  • Coding & Algorithms
  • Data Scientist

Detect k events in a sliding window

Company: Gemini

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Implement an algorithm that, for each user, determines whether there exists a set of at least k ACH credit events from distinct device_ids within any sliding window of t minutes where each amount_cents ≥ X. If so, output the earliest such window [start_ts, end_ts] and the k device_ids; otherwise output none. Input - events: iterable of (user_id INT, device_id TEXT, ts ISO-8601 string, amount_cents INT), up to n=1e6 total events across users, potentially out of order by ≤5 minutes. Parameters - k ∈ {3,4,5}; t up to 1440; X ≥ 0. Requirements - Time: O(n log n) overall; Space: O(m) where m is max events per user within t-minute horizon. - Handle out-of-order events (≤5 minutes skew) and deduplicate exact duplicates. - Timestamps are UTC; beware DST transitions and clock skew. - Return all qualifying users with their earliest window and devices. Follow-ups 1) Describe a streaming approach (bounded memory) if events arrive per user partition. 2) Prove correctness of your window advancement and distinct-device counting. 3) Discuss worst-case behavior on highly bursty users and how to mitigate.

Quick Answer: This question evaluates a candidate's ability to design efficient sliding-window and streaming algorithms for time-series event data, encompassing deduplication, handling bounded out-of-order arrivals and clock skew, distinct-device counting, and meeting specified time and space complexity constraints.

Gemini logo
Gemini
Oct 13, 2025, 9:49 PM
Data Scientist
Onsite
Coding & Algorithms
2
0

Implement an algorithm that, for each user, determines whether there exists a set of at least k ACH credit events from distinct device_ids within any sliding window of t minutes where each amount_cents ≥ X. If so, output the earliest such window [start_ts, end_ts] and the k device_ids; otherwise output none. Input

  • events: iterable of (user_id INT, device_id TEXT, ts ISO-8601 string, amount_cents INT), up to n=1e6 total events across users, potentially out of order by ≤5 minutes. Parameters
  • k ∈ {3,4,5}; t up to 1440; X ≥ 0. Requirements
  • Time: O(n log n) overall; Space: O(m) where m is max events per user within t-minute horizon.
  • Handle out-of-order events (≤5 minutes skew) and deduplicate exact duplicates.
  • Timestamps are UTC; beware DST transitions and clock skew.
  • Return all qualifying users with their earliest window and devices. Follow-ups
  1. Describe a streaming approach (bounded memory) if events arrive per user partition.
  2. Prove correctness of your window advancement and distinct-device counting.
  3. Discuss worst-case behavior on highly bursty users and how to mitigate.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 7,500+ 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.