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 98365ad commit d6f5afeCopy full SHA for d6f5afe
Python/maximum-equal-frequency.py
@@ -0,0 +1,26 @@
1
+# Time: O(n)
2
+# Space: O(n)
3
+
4
+import collections
5
6
7
+class Solution(object):
8
+ def maxEqualFreq(self, nums):
9
+ """
10
+ :type nums: List[int]
11
+ :rtype: int
12
13
+ result = 0
14
+ count = collections.Counter()
15
+ freq = [0 for _ in xrange(len(nums)+1)]
16
+ for i, n in enumerate(nums, 1):
17
+ freq[count[n]] -= 1
18
+ freq[count[n]+1] += 1
19
+ count[n] += 1
20
+ c = count[n]
21
+ if freq[c]*c == i and i < len(nums):
22
+ result = i+1
23
+ remain = i-freq[c]*c
24
+ if freq[remain] == 1 and remain in [1, c+1]:
25
+ result = i
26
+ return result
0 commit comments