You are given an integer array nums and an integer k.
Consider an operation where you pick one index and increase the value at that index by 1.
Given that you can perform this operation at most k times in total, distributed over any indices you like, return the largest count of equal elements the array can contain.
Examples
Example 1
Input: nums = [1, 2, 4], k = 5
Output: 3
Explanation: Raise the first element by 3 and the second by 2 (5 operations in total) to get [4, 4, 4]. All three elements are equal.
Example 2
Input: nums = [1, 4, 8, 13], k = 5
Output: 2
Explanation: Several choices reach two equal elements, e.g. raise the first element by 3 to get [4, 4, 8, 13]. No choice reaches three within 5 operations.
Example 3
Input: nums = [3, 9, 6], k = 2
Output: 1
Explanation: Every pair of elements differs by more than 2, so no two elements can be made equal.
Constraints
1≤nums.length≤105
1≤nums[i]≤105
1≤k≤105
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run