Skip to content

Frequency of the Most Frequent Element

MediumSliding Window
Decode it first. Clues, constraints, pattern and plan before any code.

In one operation you may increase any element of nums by 1. You can do at most k operations in total. Return the highest possible frequency (count) of any single value after your operations.

nums = [1, 2, 4],     k = 5   →  3   (raise 1 by 3 and 2 by 2: [4, 4, 4])
nums = [1, 4, 8, 13], k = 5   →  2   (e.g. raise 1 to 4)
nums = [3, 9, 6],     k = 2   →  1

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^5
  • 1 <= k <= 10^5