Finding the users active minutes

November 17, 2022

array-and-hashmap

Problem URL: Finding the users active minutes

We will use a hashset to count the unique logs for each user. Then we iterate over that, take the length of the hashset and add it to the result.

class Solution:
    def findingUsersActiveMinutes(self, logs: List[List[int]], k: int) -> List[int]:
        uams = collections.defaultdict(set)
        for _id, time in logs:
            uams[_id].add(time)

        res = [0] * k
        for uam in uams.values():
            res[len(uam)-1] += 1

        return res

Time complexity: O(n)
Space complexity: O(n)