Tap here to switch tabs
Problem
Submissions

Problem: Maximum Frequency of an Element After Operations II

Try to solve the Maximum Frequency of an Element After Performing Operations II problem.

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

Try to solve the Maximum Frequency of an Element After Performing Operations II problem.

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