Active Users in a Five-Minute Window
Updated
Problem statement
You receive a finite sequence of operations over timestamped user activity.
["add", timestamp, userId]records one request fromuserIdat the given integertimestamp.["getActiveUsers", currentTimestamp]asks for the number of distinct users with at least one recorded request in the inclusive interval[currentTimestamp - 300, currentTimestamp].
Event timestamps may arrive out of order. Query timestamps are nondecreasing, and every added event timestamp is at most the timestamp of the next query. Repeated requests from the same user count that user once while any of the user's requests remains in the active window.
Return one integer for each getActiveUsers operation, in encounter order.
Function
countActiveUsers(operations: String[][]) → int[]Examples
Example 1
operations = [["add","100","alice"],["add","250","bob"],["getActiveUsers","400"],["add","100","alice"],["getActiveUsers","401"]]return = [2,1]At time 400, both users have a request in the inclusive interval [100, 400]. At time 401, both requests at time 100 are expired, so only bob remains active.
Example 2
operations = [["add","0","u"],["add","300","v"],["getActiveUsers","300"],["getActiveUsers","301"]]return = [2,1]The request at time 0 is included when the query time is 300, then expires when the query time becomes 301.
Constraints
1 <= operations.length <= 100000.- Every operation is either
addorgetActiveUsers. 0 <= timestamp, currentTimestamp <= 1000000000.- Query timestamps are nondecreasing.
- Each added event timestamp is at most the timestamp of the next query.
userIdcontains between1and40visible ASCII characters.
More Bloomberg LP Phone Screen questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Fixed Window Average and ModeNuro · PHONE SCREENNuro interview questions
- Rate Limiter with a Sliding Window per ClientStackAdapt · PHONE SCREENStackAdapt interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Per-Client API Rate LimiterDocker · PHONE SCREEN
- Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
- Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
- Per-Client Sliding-Window Rate LimiterCVS Health · PHONE SCREEN
- Search for an Element in a StreamAmazon · PHONE SCREEN
- Build a File Tree from Streamed RecordsNextdoor · PHONE SCREENNextdoor interview questions
- Implement a Rate LimiterRoblox · PHONE SCREENRoblox interview questions