Skip to main content
Back to problems
#1817
Medium Algorithms

Finding the users active minutes

Array Hash Table
80.8% acceptance
Feb 25, 2026
863
318
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. Multiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute. 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. 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. Return the array answer as described above.

Solution

Rust
Time O(n)
Space O(n)
LeetCode
solution.rs
use std::collections::{HashMap, HashSet};


impl Solution {
  pub fn finding_users_active_minutes(logs: Vec<Vec<i32>>, k: i32) -> Vec<i32> {
    let mut user_times: HashMap<i32, HashSet<i32>> = HashMap::new();
    for log in &logs {
      user_times.entry(log[0]).or_default().insert(log[1]);
    }
    let mut answer = vec![0i32; k as usize];
    for (_, times) in &user_times {
      let uam = times.len();
      if uam >= 1 && uam <= k as usize {
        answer[uam - 1] += 1;
      }
    }
    answer
  }
}