Python · Intermediate · 35 min
Distinct accounts in time ranges
Apply half-open interval boundaries without double-counting activity.
Task
Implement distinct_accounts(events, windows). Events are (timestamp, account_id) pairs. For each window (start, end), return the number of distinct accounts whose timestamp lies in [start, end).
Requirements
- events and windows must be lists of two-item tuples or lists. Do not modify them.
- Timestamps and boundaries are integers, not bool. Account IDs are nonempty strings.
- Every window must have start < end. Overlapping windows are independent.
- Duplicate events do not increase a window’s count. Return counts in the original window order. Invalid input raises ValueError.
IntervalsDistinct countsBoundary conditions
Loading exercise…