All problems

Frequency of the Most Frequent Element

Medium · sliding window

A list nums holds whole numbers, and you are given a budget k.

In one operation you pick any position in the list and add 1 to the number there. You may do at most k operations in total, on any positions, and the same position can be picked more than once.

After you are done, some value appears in the list a certain number of times. Return the largest number of times any single value can be made to appear.

Examples

Example 1

Input: nums = [1, 2, 4], k = 5

Output: 3

Raise the 1 to 4 (three operations) and the 2 to 4 (two operations). That is five operations, and the list becomes [4, 4, 4].

Example 2

Input: nums = [1, 4, 8, 13], k = 5

Output: 2

For instance, raise the 4 to 8 with four operations. Making three equal values would cost more than 5.

Example 3

Input: nums = [3, 3, 3], k = 0

Output: 3

With no operations you cannot change anything, and the value 3 already appears three times.

Constraints