Ctrl K

Active Minutes Histogram

Medium
A service keeps an action log: events[i] = [user, minute] means that user user did something during minute minute. One user may perform several actions in the same minute, and different users may act at the same time. A user's activity is the number of distinct minutes in which they did anything. Return a list of length size where the element at index j (0-based) is the number of users whose activity is exactly j + 1 minutes.
Example 1
events=[[7, 10], [3, 10], [7, 12], [7, 10], [3, 15], [3, 16]], size=4 → [0, 1, 1, 0]

User 7 was active in minutes 10 and 12 (the second record at minute 10 does not count): 2 minutes. User 3 was active in minutes 10, 15 and 16: 3 minutes. The answer is [0, 1, 1, 0].

Example 2
events=[[0, 5], [1, 5], [2, 5]], size=2 → [3, 0]

Three users with one active minute each: [3, 0].

Constraints
  • 1 ≤ len(events) ≤ 10⁵
  • 0 ≤ user ≤ 10⁹
  • 1 ≤ minute ≤ 10⁵
  • The largest activity of any user ≤ size ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSudoku Board Without Clashes MediumAnagram Buckets MediumZero Out the Crosses MediumTree From Pre-Order and In-Order Walks MediumTree From In-Order and Post-Order Walks Medium
loading Python…
Input
events=[[7, 10], [3, 10], [7, 12], [7, 10], [3, 15], [3, 16]], size=4
Expected
[0, 1, 1, 0]

Run checks the first 3 tests in your browser. Submit checks all 110 tests on the server, hidden ones included.