-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathq1838.py
More file actions
27 lines (23 loc) · 770 Bytes
/
q1838.py
File metadata and controls
27 lines (23 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import List
class Solution:
def maxFrequency(self, nums: List[int], k: int) -> int:
nums.sort()
length = len(nums)
start = 0
sum = 0
result = 1
for i in range(length):
num = nums[i]
sum += num
if sum + k >= num * (i - start + 1):
if result < (i - start + 1):
result = i - start + 1
else:
while sum + k < num * (i - start + 1):
sum -= nums[start]
start += 1
return result
nums = [9940,9995,9944,9937,9941,9952,9907,9952,9987,9964,9940,9914,9941,9933,9912,9934,9980,9907,9980,9944,9910,9997]
k = 7925
result = Solution().maxFrequency(nums,k)
print(result)