Guest User

Untitled

a guest
Apr 23rd, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. class Solution:
  2.     def maxFrequency(self, nums: List[int], k: int) -> int:
  3.         nums.sort()
  4.  
  5.         left = 0
  6.         right = 0
  7.  
  8.         maxPossibleFrequency = 0
  9.         previousHeight = nums[0]
  10.         area = 0
  11.  
  12.         while right < len(nums):
  13.             deltaHeight = nums[right] - previousHeight
  14.             width = right - left
  15.             area += width * deltaHeight
  16.  
  17.             while area > k:
  18.                 area -= nums[right] - nums[left]
  19.                 left += 1
  20.  
  21.             previousHeight = nums[right]
  22.             right += 1
  23.             maxPossibleFrequency = max(maxPossibleFrequency, right - left)
  24.  
  25.         return maxPossibleFrequency
Advertisement
Add Comment
Please, Sign In to add comment