Skip to content

Commit c141dfe

Browse files
authored
Create frequency-of-the-most-frequent-element.py
1 parent a57acd4 commit c141dfe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(nlogn)
2+
# Space: O(n)
3+
4+
class Solution(object):
5+
def maxFrequency(self, nums, k):
6+
"""
7+
:type nums: List[int]
8+
:type k: int
9+
:rtype: int
10+
"""
11+
left = 0
12+
nums.sort()
13+
for right in xrange(len(nums)):
14+
k += nums[right]
15+
if k < nums[right]*(right-left+1):
16+
k -= nums[left]
17+
left += 1
18+
return right-left+1

0 commit comments

Comments
 (0)