1817. Finding the Users Active Minutes Medium

@problem@discussion
#Array#Hash Table



1/**
2 * [1817] Finding the Users Active Minutes
3 *
4 * You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDi performed an action at the minute timei.
5 * Multiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute.
6 * The user active minutes (UAM) for a given user is defined as the number of unique minutes in which the user performed an action on LeetCode. A minute can only be counted once, even if multiple actions occur during it.
7 * You are to calculate a 1-indexed array answer of size k such that, for each j (1 <= j <= k), answer[j] is the number of users whose UAM equals j.
8 * Return the array answer as described above.
9 *  
10 * Example 1:
11 * 
12 * Input: logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5
13 * Output: [0,2,0,0,0]
14 * Explanation:
15 * The user with ID=0 performed actions at minutes 5, 2, and 5 again. Hence, they have a UAM of 2 (minute 5 is only counted once).
16 * The user with ID=1 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.
17 * Since both users have a UAM of 2, answer[2] is 2, and the remaining answer[j] values are 0.
18 * 
19 * Example 2:
20 * 
21 * Input: logs = [[1,1],[2,2],[2,3]], k = 4
22 * Output: [1,1,0,0]
23 * Explanation:
24 * The user with ID=1 performed a single action at minute 1. Hence, they have a UAM of 1.
25 * The user with ID=2 performed actions at minutes 2 and 3. Hence, they have a UAM of 2.
26 * There is one user with a UAM of 1 and one with a UAM of 2.
27 * Hence, answer[1] = 1, answer[2] = 1, and the remaining values are 0.
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= logs.length <= 10^4
33 * 	0 <= IDi <= 10^9
34 * 	1 <= timei <= 10^5
35 * 	k is in the range [The maximum UAM for a user, 10^5].
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/finding-the-users-active-minutes/
41// discuss: https://leetcode.com/problems/finding-the-users-active-minutes/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn finding_users_active_minutes(logs: Vec<Vec<i32>>, k: i32) -> Vec<i32> {
47        vec![]
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_1817() {
59    }
60}
61


Back
© 2025 bowen.ge All Rights Reserved.