LeetCode: Finding The Users Active Minutes Solution
1/**2 * @param {number[][]} logs3 * @param {number} k4 * @return {number[]}5 */6var findingUsersActiveMinutes = function (logs, k) {7 const res = Array(k).fill(0)89 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 acc15 }, new Map())1617 for (const userMinSet of map.values()) {18 res[userMinSet.size - 1]++19 }2021 return res22}
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.