Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def maxFrequency(self, nums: List[int], k: int) -> int:
- nums.sort()
- left = 0
- right = 0
- maxPossibleFrequency = 0
- previousHeight = nums[0]
- area = 0
- while right < len(nums):
- deltaHeight = nums[right] - previousHeight
- width = right - left
- area += width * deltaHeight
- while area > k:
- area -= nums[right] - nums[left]
- left += 1
- previousHeight = nums[right]
- right += 1
- maxPossibleFrequency = max(maxPossibleFrequency, right - left)
- return maxPossibleFrequency
Advertisement
Add Comment
Please, Sign In to add comment