A company has several employees who do the same job but earn different salaries. To move toward equal pay, the company will give raises so that as many employees as possible end up earning exactly the same salary.
Salaries can only be raised, never lowered. Raising a salary by 1 uses 1 unit of the raise budget, so a raise from 60 to 64 uses 4 units. All raises together must stay within raiseBudget units, and the budget does not have to be fully used.
Return the maximum number of employees who can end up earning the same salary. Employees outside this group keep their current salaries.
int maxEqualPayGroup(List<Integer> salaries, int raiseBudget)
salaries.get(i) is the current salary of employee i.raiseBudget is the total number of units that can be spent on raises.1.1 ≤ salaries.size() ≤ 100,0001 ≤ salaries.get(i) ≤ 100,0001 ≤ raiseBudget ≤ 100,000Input: maxEqualPayGroup(salaries = [52, 47, 50, 58, 49], raiseBudget = 6)
Output: 3
Explanation: Raise 47 and 49 to 50, which uses 3 + 1 = 4 units. Three employees now earn 50. A group of four would need at least 10 units.
Input: maxEqualPayGroup(salaries = [70, 66, 70, 68, 70, 61], raiseBudget = 3)
Output: 4
Explanation: Three employees already earn 70. Raising 68 to 70 uses 2 units, so four employees earn 70. Raising 66 as well would need 4 more units, but only 1 unit is left.
Input: maxEqualPayGroup(salaries = [90, 31, 34, 33, 95], raiseBudget = 4)
Output: 3
Explanation: Raise 31 to 34 (3 units) and 33 to 34 (1 unit). This uses the whole budget, and three employees earn 34. The two highest salaries, 90 and 95, are 5 apart, so they cannot be matched.
Input: maxEqualPayGroup(salaries = [20, 35, 50], raiseBudget = 14)
Output: 1
Explanation: Any two salaries are at least 15 apart, which is more than the budget. No two employees can be matched.
Input: maxEqualPayGroup(salaries = [40, 42, 41], raiseBudget = 5)
Output: 3
Explanation: Raise 40 and 41 to 42, which uses 2 + 1 = 3 units. All three employees now earn 42, and the other 2 units are not used.