Problem · Combinatorics
EasyIBMOA
See IBM hiring insights

Problem statement

FC Codelona is trying to assemble a team from a roster of available players. They have a minimum number of players they want to sign, and each player needs to have a skill rating within a certain range.

Given a list of players' skill levels with desired upper and lower bounds, determine how many teams can be created from the list.

Function

countTeams(skills: int[], minPlayers: int, minLevel: int, maxLevel: int) → int

Complete the function countTeams in the editor.

countTeams has the following parameters:

  1. 1. int[] skills: an array of integers representing the skill levels of players
  2. 2. int minPlayers: the minimum number of players required to form a team
  3. 3. int minLevel: the minimum skill level required for a player to be eligible
  4. 4. int maxLevel: the maximum skill level required for a player to be eligible

Returns

int: the number of ways to form a team that meets the criteria

Examples

Example 1

skills = [12, 4, 6, 13, 5, 10]minPlayers = 3minLevel = 4maxLevel = 10return = 5

The list includes players with skill levels [12, 4, 6, 13, 5, 10].

They want to hire at least 3 players with skill levels between 4 and 10, inclusive.

Four of the players with the following skill levels {4, 6, 5, 10} meet the criteria.

There are 5 ways to form a team of at least 3 players: {4, 5, 6}, {4, 6, 10}, {4, 5, 10}, {5, 6, 10}, and {4, 5, 6, 10}.

Return 5.

Constraints

🍇🍇

More IBM problems

drafts saved locally
public int countTeams(int[] skills, int minPlayers, int minLevel, int maxLevel) {
  // write your code here
}
skills[12, 4, 6, 13, 5, 10]
minPlayers3
minLevel4
maxLevel10
expected5
checking account