Watch 10 video solutions for Maximum Frequency of an Element After Performing Operations II, a hard level problem involving Array, Binary Search, Sliding Window. This walkthrough by CrioDo has 304,699 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
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:
i that was not selected in any previous operations.[-k, k] to nums[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 = 2
Output: 2
Explanation:
We can achieve a maximum frequency of two by:
nums[1], after which nums becomes [1, 4, 5].nums[2], after which nums becomes [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:
nums[1].
Constraints:
1 <= nums.length <= 1051 <= nums[i] <= 1090 <= k <= 1090 <= numOperations <= nums.length