#3346

Maximum Frequency of an Element After Performing Operations I

medium · 40.1% accepted · 614 likes · top 19%

array · binary search · sliding window · sorting · prefix sum

⊣ practice⊣ open on leetcode ↗

Description

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 i that was not selected in any previous operations.

- Add an integer in the range [-k, k] to nums[i].

Return the maximum possible frequency of any element in nums after performing the operations.

Solution