We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 00d363c commit 2402e98Copy full SHA for 2402e98
scripts/algorithms/C/Count Largest Group/Count Largest Group.js
@@ -1,25 +1,26 @@
1
+// Runtime: 146 ms (Top 27.63%) | Memory: 47.5 MB (Top 55.26%)
2
var countLargestGroup = function(n) {
3
const hash = {};
4
5
for (let i = 1; i <= n; i++) {
6
const sum = i.toString().split('').reduce((r, x) => r + parseInt(x), 0);
-
7
+
8
if (!hash[sum]) {
9
hash[sum] = 0;
10
}
11
12
hash[sum]++;
13
14
15
return Object.keys(hash)
16
.sort((a, b) => hash[b] - hash[a])
17
.reduce((res, x) => {
18
const prev = res[res.length - 1];
19
20
if (!prev || prev === hash[x]) {
21
res.push(hash[x]);
22
23
24
return res;
25
}, []).length;
-};
26
+};
0 commit comments