Finding the Users Active Minutes - Problem
Imagine you're a data analyst at a coding platform tracking user engagement patterns. You have access to user activity logs and need to understand how many users are active for specific durations.
Given a 2D integer array logs where each logs[i] = [IDi, timei] represents that user IDi performed an action at minute timei, and an integer k, your task is to analyze user engagement patterns.
Key Points:
- Multiple users can be active simultaneously
- A user can perform multiple actions in the same minute (but it counts as 1 active minute)
- User Active Minutes (UAM) = number of unique minutes a user was active
Return a 1-indexed array of size k where answer[j] represents the number of users whose UAM equals j.
Example: If 3 users were active for exactly 2 minutes each, then answer[2] = 3.
Input & Output
example_1.py โ Basic Case
$
Input:
logs = [[1,1],[2,2],[1,3],[3,1]], k = 4
โบ
Output:
[2,1,0,0]
๐ก Note:
User 1: active at minutes 1 and 3 โ UAM = 2. User 2: active at minute 2 โ UAM = 1. User 3: active at minute 1 โ UAM = 1. So we have 2 users with UAM=1, 1 user with UAM=2, and 0 users with UAM=3 or UAM=4.
example_2.py โ Duplicate Activities
$
Input:
logs = [[0,5],[1,2],[0,2],[0,5],[1,3]], k = 5
โบ
Output:
[0,2,0,0,0]
๐ก Note:
User 0: active at minutes 2 and 5 (minute 5 counted once) โ UAM = 2. User 1: active at minutes 2 and 3 โ UAM = 2. Both users have UAM=2, so answer[1] = 2.
example_3.py โ Single User Multiple Times
$
Input:
logs = [[1,1],[1,1],[1,1]], k = 1
โบ
Output:
[1]
๐ก Note:
User 1 performs multiple actions at minute 1, but it only counts as 1 unique active minute. So UAM = 1, and answer[0] = 1.
Constraints
- 1 โค logs.length โค 104
- 0 โค IDi โค 109
- 1 โค timei โค 105
- 1 โค k โค 1000
- logs[i].length == 2
Visualization
Tap to expand
Understanding the Visualization
1
Record Visits
Track each customer's unique visit hours using a hash map
2
Count Patterns
Group customers by their total unique visit hours
3
Generate Report
Create frequency report showing engagement distribution
Key Takeaway
๐ฏ Key Insight: Hash tables efficiently deduplicate activities per user and enable fast frequency counting for engagement analysis
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code