We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d8966d4 commit ebb64cbCopy full SHA for ebb64cb
1224-maximum-equal-frequency.js
@@ -1,3 +1,41 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number}
4
+ */
5
+const maxEqualFreq = function (nums) {
6
+ const freqCnt = {}, cnt = {}, { max } = Math
7
+
8
+ let res = 0, maxF = 0, i = 0
9
+ for(const e of nums) {
10
+ if(cnt[e] == null) cnt[e] = 0
11
+ cnt[e]++
12
13
+ const f = cnt[e]
14
15
+ if(freqCnt[f - 1] == null) freqCnt[f - 1] = 0
16
+ if(freqCnt[f] == null) freqCnt[f] = 0
17
18
+ if(freqCnt[f - 1] > 0) freqCnt[f - 1]--
19
+ freqCnt[f]++
20
21
+ maxF = max(maxF, f)
22
23
+ if(
24
+ maxF === 1 ||
25
+ maxF * freqCnt[maxF] === i ||
26
+ (maxF - 1) * (freqCnt[maxF - 1] + 1) === i
27
+ ) {
28
+ res = i + 1
29
+ }
30
31
+ i++
32
33
34
+ return res
35
+}
36
37
+// another
38
39
/**
40
* @param {number[]} nums
41
* @return {number}
0 commit comments