Skip to content

Commit e24c5a6

Browse files
authored
Added Finding the Users Active Minutes.java
1 parent fd23399 commit e24c5a6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public int[] findingUsersActiveMinutes(int[][] logs, int k) {
3+
Map<Integer, Set<Integer>> map = new HashMap<>();
4+
List<Set<Integer>> setList = new ArrayList<>();
5+
for (int i = 0; i < k; i++) {
6+
setList.add(new HashSet<>());
7+
}
8+
for (int[] log : logs) {
9+
map.computeIfAbsent(log[0], j -> new HashSet<>()).add(log[1]);
10+
int currActiveTime = map.get(log[0]).size();
11+
if (currActiveTime <= k) {
12+
setList.get(currActiveTime - 1).add(log[0]);
13+
if (currActiveTime != 1) {
14+
setList.get(currActiveTime - 2).remove(log[0]);
15+
}
16+
}
17+
}
18+
int[] ans = new int[k];
19+
for (int i = 0; i < k; i++) {
20+
ans[i] = setList.get(i).size();
21+
}
22+
return ans;
23+
}
24+
}

0 commit comments

Comments
 (0)