Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

Bloomberg interview question

Count distinct users active in the last five minutes of a request log

Company:
Bloomberg
Type:
Coding
Difficulty:
Medium
Reported:
October 19, 2026

Problem

Implement a request-log aggregator with two operations:

  • record(timestamp, user_id): log that user_id made a request at timestamp.
  • count(now): return the number of distinct users who made at least one request in the five minutes up to now.

A user who made several requests inside the window is counted once. Requests are not guaranteed to be recorded in timestamp order: a request can be logged after requests that carry later timestamps.

Timestamps in the examples are in seconds, so the window is the 300 seconds ending at now. Whether a request exactly 300 seconds old still counts is a boundary convention to agree on; either consistent choice is accepted, and the examples avoid that case.

Example 1

Input:  record(10, "u1"), record(20, "u2"), record(30, "u1"), record(200, "u3"),
        count(305), count(325), count(331)
Output: 3, 2, 1

At 305 all three users have a request in the last 300 seconds. At 325, u2's only request (at 20) is too old, but u1's request at 30 keeps u1 active. At 331, u1 has expired too and only u3 remains.

Example 2

Input:  record(400, "a"), record(100, "b"), record(350, "b"), count(420),
        record(380, "c"), count(430)
Output: 2, 3

The request of "b" at 100 is logged after the request at 400, and on its own it is too old at 420, but "b" also requested at 350. The request of "c" at 380 is logged after count(420) and still counts at 430.

Constraints

  • Requests may be recorded in any timestamp order, and one user can appear any number of times.
  • count may be called at any point, with any now.

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern