Count Distinct Signed-In Users in Every Window of K Events

Last updated: November 29, 2026

Quick Overview

Given a sequence of user IDs from consecutive sign-in events and an integer k, return the number of distinct users in each contiguous window of k events.

Google
Coding & Algorithms
Data Engineer
Google
November 29, 2026
Data Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a sequence of user IDs from consecutive sign-in events and an integer k, return the number of distinct users in each contiguous window of k events.

Framed around a Google Workspace sign-in monitor that flags bursts of distinct accounts, this checks a fixed-size window backed by a frequency map. The interviewer wants O(1) updates per step and correct removal of users whose count drops to zero.

What the Interviewer Expects
  • Maintains a frequency dictionary for the current window
  • Deletes keys when their count reaches zero
  • Emits a result for each of the n - k + 1 windows
  • Handles k larger than the input
  • States O(n) time and O(k) space
Key Topics to Cover
Sliding Window
Hash Map
Frequency Counting
Streaming
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
  • How would you approximate this with bounded memory for very large windows (for example, HyperLogLog)?
  • What if windows are defined by time (last 5 minutes) instead of event count?
  • How would you shard this across machines by tenant?
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: list users, integer k >= 1.
  • Output: list of length n - k + 1 where entry i is the number of distinct IDs in users[i:i+k].
  • If k > n, return an empty list....
High-Level Design

Keep a dictionary from user ID to its count inside the window. Add each new event; once the window has more than k events, decrement the count for the event that just left and delete the key when it...


Submit Your Answer
Markdown supported