Problem · Sorting

Equalize Team Size

Learn this problem
MediumIBMNEW GRADOA
See IBM hiring insights

Problem statement

HackerRank is organizing a hackathon for all its employees.

A hackathon is a team event, and there are n teams taking part. The number of employees in the nth team is denoted by teamSize[n]. In order to maintain uniformity, the team size of at most k teams can be reduced. Find the maximum number of teams of equal size that can be formed if team size is reduced optimally.

Function

equalizeTeamSize(teamSize: int[], k: int) → int

Complete the function equalizeTeamSize in the editor below.

equalizeTeamSize has the following parameters:

  1. int teamSize[n]: the number of employees in each team
  2. int k: the maximum number of teams whose size can be reduced

Returns

int: the maximum number of equal size teams possible

Examples

Example 1

teamSize = [1, 2, 2, 3, 4]k = 2return = 4

The team size of the last 2 teams can be reduced to 2, thus teamSize = [1, 2, 2, 2, 2]. The maximum number of teams with equal size is 4.

Constraints

  • 1 ≤ n ≤ 2 * 10^5
  • 1 ≤ teamSize[i] ≤ 10^9
  • 0 ≤ k ≤ 10^9
  • More IBM problems

    drafts saved locally
    public int equalizeTeamSize(int[] teamSize, int k) {
      // write your code here
    }
    
    teamSize[1, 2, 2, 3, 4]
    k2
    expected4
    checking account