Class Solution
-
- All Implemented Interfaces:
public final class Solution3347 - Maximum Frequency of an Element After Performing Operations II.
Hard
You are given an integer array
numsand two integerskandnumOperations.You must perform an operation
numOperationstimes onnums, 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
numsafter performing the operations.Example 1:
Input: nums = 1,4,5, k = 1, numOperations = 2
Output: 2
Explanation:
We can achieve a maximum frequency of two by:
Adding 0 to
nums[1], after whichnumsbecomes[1, 4, 5].Adding -1 to
nums[2], after whichnumsbecomes[1, 4, 4].
Example 2:
Input: nums = 5,11,20,20, k = 5, numOperations = 1
Output: 2
Explanation:
We can achieve a maximum frequency of two by:
Adding 0 to
nums[1].
Constraints:
<code>1 <= nums.length <= 10<sup>5</sup></code>
<code>1 <= numsi<= 10<sup>9</sup></code>
<code>0 <= k <= 10<sup>9</sup></code>
0 <= numOperations <= nums.length