You are given the action logs of users on an online platform and an integer k. The logs are a 2D integer array logs where each logs[i] = [id_i, time_i] means the user with ID id_i performed an action at minute time_i.
Several users can act in the same minute, and one user can perform several actions in the same minute.
The user active minutes (UAM) of a user is the number of unique minutes in which that user performed at least one action. A minute counts once for a user, even if the user performed several actions during it.
Compute an array answer of size k such that, for each j with 1 <= j <= k, the entry for j is the number of users whose UAM equals j. The array is 1-indexed in this description, so in the returned Python list answer[j - 1] holds the count for UAM j.
Return answer.
Function Signature
def finding_users_active_minutes(logs: list[list[int]], k: int) -> list[int]:
Rules
-
Each entry of
logs
is a pair
[user_id, minute]
.
-
The returned list has exactly
k
entries. Position
j - 1
holds the number of users whose UAM equals
j
.
-
A user whose UAM is greater than
k
is not counted in any position.
-
Only users who appear in
logs
are counted, so no user has a UAM of 0.
Constraints
-
1 <= logs.length <= 10^4
-
0 <= id_i <= 10^9
-
1 <= time_i <= 10^5
-
1 <= k <= 10^5
Examples
Input: logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5
Output: [0,2,0,0,0]
User 0 acted at minutes 5 and 2 (minute 5 appears twice but counts once), so its UAM is 2. User 1 acted at minutes 2 and 3, so its UAM is also 2, and the position for UAM 2 holds 2.
Input: logs = [[1,1],[2,2],[2,3]], k = 4
Output: [1,1,0,0]
User 1 has UAM 1 (minute 1 only) and user 2 has UAM 2 (minutes 2 and 3), so the positions for UAM 1 and UAM 2 each hold 1.
Input: logs = [[7,1],[7,2],[7,3],[8,4]], k = 2
Output: [1,0]
User 7 has UAM 3, which is greater than k, so it is not counted. User 8 has UAM 1.