Maximum Frequency of an Element After Performing Operations I
You are given an integer array nums and two integers k and numOperations.
You must perform an operation numOperations times on nums, where in each operation you:
- Select an index
ithat was not selected in any previous operations. - Add an integer in the range
[-k, k]tonums[i].
Return the maximum possible frequency of any element in nums after performing the operations.
Example 1
Input
nums = [1,4,5], k = 1, numOperations = 2Output
2We can make two elements equal to 4 by adding 0 to nums[1] and -1 to nums[2].
Example 2
Input
nums = [5,11,20,20], k = 5, numOperations = 1Output
2With one operation, adding 0 to nums[1] keeps the two 20 values as the maximum frequency of two.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^5
- 0 <= k <= 10^5
- 0 <= numOperations <= nums.length