Finding the Users Active Minutes - Problem

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. A minute can only be counted once, even if multiple actions occur during it.

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.

Input & Output

Example 1 — Basic Case
$ Input: logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5
Output: [0,2,0,0,0]
💡 Note: User 0 has UAM=2 (minutes 2,5), User 1 has UAM=2 (minutes 2,3). So 0 users have UAM=1, 2 users have UAM=2, and 0 users have UAM=3,4,5.
Example 2 — Single User
$ Input: logs = [[1,1],[1,2],[1,3]], k = 4
Output: [0,0,1,0]
💡 Note: User 1 has UAM=3 (minutes 1,2,3). So 1 user has UAM=3, others are 0.
Example 3 — Duplicate Minutes
$ Input: logs = [[0,1],[0,1],[1,1]], k = 3
Output: [2,0,0]
💡 Note: User 0 has UAM=1 (minute 1 counted once), User 1 has UAM=1 (minute 1). So 2 users have UAM=1.

Constraints

  • 1 ≤ logs.length ≤ 104
  • 0 ≤ IDi ≤ 109
  • 1 ≤ timei ≤ 105
  • k is in the range [1, logs.length]

Visualization

Tap to expand
Users Active Minutes (UAM) ProblemInput: logs[0,5][1,2][0,2]Group by UserUser 0:{2,5}User 1:{2,3}Output: UAM CountUAM=2: 2 users[0,2,0,0,0]k=5 → Result: [0,2,0,0,0]
Understanding the Visualization
1
Input Logs
2D array of [userID, minute] pairs
2
Group by User
Collect unique minutes for each user
3
Count UAM
Count how many users have each UAM value
Key Takeaway
🎯 Key Insight: Group logs by user first, count unique minutes, then frequency count by UAM
Asked in
LeetCode 15 Amazon 8
12.0K Views
Medium Frequency
~15 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen