Description Link to heading

1817.finding-the-users-active-minutes

Solution Link to heading

We can use unordered_map<int, unordered_set<int>> mp to record the id and time_i that they operate.

We can use unordered_map<int, int> mins to record the minutes and their number of users.

Code Link to heading

class Solution {
public:
    vector<int> findingUsersActiveMinutes(vector<vector<int>>& logs, int k) {
        unordered_map<int, unordered_set<int>> mp;
        for (auto &vec : logs) {
            mp[vec[0]].insert(vec[1]);
        }
        unordered_map<int, int> mins;
        int num = mp.size();
        vector<int> ans(k, 0);
        for (auto iter = mp.begin(); iter != mp.end(); iter++) {
            mins[(iter->second).size()]++;
        }
        for (int i = 0; i < k; i++) {
            if (mins.find(i + 1) != mins.end())
                ans[i] = mins[i + 1];
            else
                ans[i] = 0;
        }
        return ans;
    }
};