Frequency of the Most Frequent Element

Given an array of integers and an integer k, return the maximum possible frequency of the most frequent element after at most k increments. Sorting is required because the optimal window grows over ordered values.

Input Format

nums = array of integers, k = number of increments allowed

Output Format

maximum achievable frequency

Constraints

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

Examples

Example 1:

Input:

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

Output:

3

Explanation:

Increase 1 and 2 to 4 using 5 increments total.

Example 2:

Input:

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

Output:

2

Explanation:

The best you can do is make two elements equal.

Loading...
Frequency of the Most Frequent Element