2
public int[] findingUsersActiveMinutes(int[][] logs, int k) {3
// create a hashmap to record the ids of users4
// and a set to store the minutes in which they were active5
Map<Integer, Set<Integer>> map = new HashMap<>();7
// l[0] -> id, l[1] -> active minute8
map.putIfAbsent(l[0], new HashSet<>()); // if new id9
map.get(l[0]).add(l[1]); // add the minute of activeness to the set12
// create answer array13
int[] ans = new int[k];14
for (int id : map.keySet()) {15
// the set contains all the minutes in which the id was active16
// so the set size will be the number of active minutes17
// or the 'User Active Minutes' (UAM)18
int uam = map.get(id).size();19
// each index in ans array is a UAM,20
// and we need to put the number of users having that UAM21
// whenever we enocunter a UAM, we increment the value in array22
// which means we have found one more user with the same UAM23
ans[uam - 1]++; // since array is 1 based indexing, we substract 126
return ans; // return ans array