Leetcode 1817: Finding the Users Active Minutes

grid47
grid47
Exploring patterns and algorithms
May 9, 2024 5 min read

Given the logs of users’ actions on a platform, calculate the number of users with each possible User Active Minutes (UAM) from 1 to k.
Problem
Approach
Steps
Complexity
Input: The input consists of a 2D array where each log entry is a pair of [ID, time], and an integer k.
Example: logs = [[0, 3], [1, 1], [0, 1], [0, 3], [1, 2]], k = 3
Constraints:
• 1 <= logs.length <= 10^4
• 0 <= IDi <= 10^9
• 1 <= timei <= 10^5
• k is in the range [1, 100000].
Output: Return a 1-indexed array where each index j corresponds to the number of users with exactly j User Active Minutes (UAM).
Example: Output: [0, 2, 0]
Constraints:
• The output array should have length k.
Goal: Count the number of users who have UAM equal to each value from 1 to k.
Steps:
• Use a hashmap to track unique action times for each user.
• Calculate the UAM for each user (the size of the unique action times).
• Count the occurrences of each UAM and store them in the result array.
Goal: The input and output should adhere to the following constraints.
Steps:
• Each log entry has an integer ID and a time value.
• The UAM count for each user is based on unique action times only.
Assumptions:
• The logs will contain valid user IDs and times within the given ranges.
• Multiple actions at the same minute by the same user are counted as a single active minute.
Input: logs = [[0, 3], [1, 1], [0, 1], [0, 3], [1, 2]], k = 3
Explanation: User 0 has a UAM of 2, User 1 has a UAM of 2, so the result is [0, 2, 0].

Input: logs = [[2, 10], [1, 1], [1, 2], [2, 10], [2, 12]], k = 4
Explanation: User 1 has UAM of 2, User 2 has UAM of 2, the result is [1, 1, 0, 1].

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus