Skip to content
Decoder

Frequency of the Most Frequent Element

Medium

Problem

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.

Example 1

Input
nums = [1, 2, 4], k = 5
Output
3
Why
raise 1 by 3 and 2 by 2: [4, 4, 4]

Example 2

Input
nums = [1, 4, 8, 13], k = 5
Output
2
Why
e.g. raise 1 to 4

Example 3

Input
nums = [3, 9, 6], k = 2
Output
1

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.