Magicsheet logo

Finding the Users Active Minutes

Medium
89.4%
Updated 6/1/2025

Asked by 3 Companies

Finding the Users Active Minutes

1. What is this problem about?

The Finding the Users Active Minutes interview question is a data analysis challenge. You are given a list of user logs, where each log contains a user_id and a time (minute) of an action. A "User Active Minute" (UAM) is a unique minute during which a user performed at least one action. Your task is to calculate the UAM for each user and then return an array where the value at index ii is the number of users who had a UAM of exactly i+1i+1.

2. Why is this asked in interviews?

Companies like Twitter and Amazon ask the Finding the Users Active Minutes coding problem to evaluate a candidate's ability to handle data deduplication and frequency counting. It tests your proficiency with Hash Table interview patterns, specifically nested structures like a map of sets. It evaluations if you can efficiently process log data to extract higher-level statistics.

3. Algorithmic pattern used

This problem follows the Deduplication and Frequency Counting pattern.

  1. Deduplicate Logs: Use a Hash Map where the key is user_id and the value is a Hash Set of unique minutes. This automatically handles multiple actions in the same minute.
  2. Calculate UAMs: Iterate through the map. For each user, their UAM is the size of their corresponding set.
  3. Frequency Count: Create a result array of size k. Iterate through the UAM values and increment the count at result[uam - 1].

4. Example explanation

Logs: [[1, 5], [2, 2], [1, 5], [1, 2], [2, 2]], k=5k=5.

  1. User 1: Minutes {5, 5, 2}. Unique: {5, 2}. UAM = 2.
  2. User 2: Minutes {2, 2}. Unique: {2}. UAM = 1.
  3. UAM Counts: One user with UAM 1, one user with UAM 2. Result: [1, 1, 0, 0, 0].

5. Common mistakes candidates make

  • Double Counting: Failing to use a Set to handle multiple logs for the same user in the same minute.
  • Off-by-one: Mistakes in the result array indexing (index 0 corresponds to UAM 1).
  • Efficiency: Using a list and searching it (O(N2)O(N^2)) instead of a Hash Map/Set (O(N)O(N)).

6. Interview preparation tip

Whenever you hear "unique occurrence" or "deduplication," immediately think of a Set. Mastering the "Map of Sets" pattern is a vital Hash Table interview pattern for data analysis questions.

Similar Questions