Apply Operations to Maximize Frequency Score
You are given a 0-indexed integer array nums and an integer k.
You can perform the following operation on the array at most k times:
- Choose any index
ifrom the array and increase or decreasenums[i]by1.
The score of the final array is the frequency of the most frequent element in the array.
Return the maximum score you can achieve.
The frequency of an element is the number of occurences of that element in the array.
Example 1
Input
nums = [1,2,6,4], k = 3Output
3By changing values to make three elements equal to 2, the most frequent element has frequency 3, and no better score is possible.
Example 2
Input
nums = [1,4,4,2,4], k = 0Output
3No operations can be applied, so the score is the frequency of the most frequent element in the original array, which is 3.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^9
- 0 <= k <= 10^14