Tap here to switch tabs
Problem
Submissions

Problem: Maximum Frequency of an Element After Operations II

Maximum Frequency of an Element After Operations II asks for the largest count of equal values after changing a limited number of distinct array elements by integers within a specified range.

Statement

You are given an integer array nums and two integers k and numOperations.

You can perform at most numOperations operations on the array. In each operation, you choose an index i that has not been chosen in any previous operation and add an integer from the range [−‘k‘,‘k‘][ -`k`, `k` ] to nums[i].

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

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤109\leq 10^9

  • 0≤0 \leq numOperations ≤\leq nums.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Frequency of an Element After Operations II

Maximum Frequency of an Element After Operations II asks for the largest count of equal values after changing a limited number of distinct array elements by integers within a specified range.

Statement

You are given an integer array nums and two integers k and numOperations.

You can perform at most numOperations operations on the array. In each operation, you choose an index i that has not been chosen in any previous operation and add an integer from the range [−‘k‘,‘k‘][ -`k`, `k` ] to nums[i].

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

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤109\leq 10^9

  • 0≤0 \leq numOperations ≤\leq nums.length