LeetCode: Finding The Users Active Minutes Solution

1/**
2 * @param {number[][]} logs
3 * @param {number} k
4 * @return {number[]}
5 */
6var findingUsersActiveMinutes = function (logs, k) {
7 const res = Array(k).fill(0)
8
9 const map = logs.reduce((acc, [userId, min]) => {
10 if (!acc.has(userId)) {
11 acc.set(userId, new Set())
12 }
13 acc.set(userId, acc.get(userId).add(min))
14 return acc
15 }, new Map())
16
17 for (const userMinSet of map.values()) {
18 res[userMinSet.size - 1]++
19 }
20
21 return res
22}

Comments

Loading comments...

Tags

leetcode

hash table

Apply and earn a $2,500 bonus once you're hired on your first job!

Clients from the Fortune 500 to Silicon Valley startups

Choose your own rate, get paid on time

From hourly, part-time, to full-time positions

Flexible remote working environment

A lot of open JavaScript jobs!!

Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.

Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.

Next Post

LeetCode: Truncate Sentence

Apr 4, 2021

HoningJS

Search Posts