Count distinct events in a half-open window
Implement window_counts(events, start, end), counting first-seen logical events by entity within [start,end). A logical event key is (source,id).
Your task
- Reject end <= start with ValueError.
- Deduplicate before window filtering: the first occurrence of a logical key determines its entity and time.
- Count only events whose time is at least start and strictly below end.
- Return a dictionary of entity counts, omit zero-count entities, and do not mutate events.
Examples
EXAMPLE 1
InputTwo deliveries of s1/e1 at time 10 for api; window [0,20)
Output{'api': 1}
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor