Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 88b8ce7

Browse files
committedJan 10, 2023
Add solution #1817
1 parent fe92a20 commit 88b8ce7

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
1780|[Check if Number is a Sum of Powers of Three](./1780-check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
283283
1791|[Find Center of Star Graph](./1791-find-center-of-star-graph.js)|Easy|
284284
1812|[Determine Color of a Chessboard Square](./1812-determine-color-of-a-chessboard-square.js)|Easy|
285+
1817|[Finding the Users Active Minutes](./1817-finding-the-users-active-minutes.js)|Medium|
285286
1832|[Check if the Sentence Is Pangram](./1832-check-if-the-sentence-is-pangram.js)|Easy|
286287
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
287288
1886|[Determine Whether Matrix Can Be Obtained By Rotation](./1886-determine-whether-matrix-can-be-obtained-by-rotation.js)|Easy|
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* 1817. Finding the Users Active Minutes
3+
* https://leetcode.com/problems/finding-the-users-active-minutes/
4+
* Difficulty: Medium
5+
*
6+
* You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented
7+
* by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDi
8+
* performed an action at the minute timei.
9+
*
10+
* Multiple users can perform actions simultaneously, and a single user can perform multiple actions
11+
* in the same minute.
12+
*
13+
* The user active minutes (UAM) for a given user is defined as the number of unique minutes in which
14+
* the user performed an action on LeetCode. A minute can only be counted once, even if multiple actions
15+
* occur during it.
16+
*
17+
* You are to calculate a 1-indexed array answer of size k such that, for each j (1 <= j <= k), answer[j]
18+
* is the number of users whose UAM equals j.
19+
*
20+
* Return the array answer as described above.
21+
*/
22+
23+
/**
24+
* @param {number[][]} logs
25+
* @param {number} k
26+
* @return {number[]}
27+
*/
28+
var findingUsersActiveMinutes = function(logs, k) {
29+
const map = new Map();
30+
logs.forEach(([id, time]) => {
31+
map.set(id, map.get(id) || new Set());
32+
map.get(id).add(time);
33+
});
34+
35+
const result = new Array(k).fill(0);
36+
[...map.values()].forEach(({ size }) => result[size - 1]++);
37+
38+
return result;
39+
};

0 commit comments

Comments
 (0)
Please sign in to comment.