FastPrepCount Valid Teams

Count Valid Teams

Wells Fargo logoWells Fargo● MediumFULLTIMEOA
Learn

Problem statement

You are given an integer array skills, where each value is one player's skill level. A player is eligible when their skill is between lowerBound and upperBound, inclusive.

A team is any subset of eligible players containing at least minPlayers players. Players are distinct even when they have equal skill values.

Return the exact number of valid teams. If fewer than minPlayers players are eligible, return 0.

Function

countValidTeams(skills: int[], minPlayers: int, lowerBound: int, upperBound: int) → long

Examples

Example 1

skills = [1,2,3]minPlayers = 2lowerBound = 1upperBound = 3return = 4

All three players are eligible. There are three two-player teams and one three-player team.

Example 2

skills = [4,8,5,6]minPlayers = 2lowerBound = 7upperBound = 8return = 0

Only the player with skill 8 is eligible, so no team can contain two players.

Example 3

skills = [1,2,3,4]minPlayers = 1lowerBound = 2upperBound = 3return = 3

Two players are eligible. Their two singleton teams and the team containing both are valid.

Constraints

  • 1 <= skills.length <= 60.
  • -10^9 <= skills[i] <= 10^9.
  • 1 <= minPlayers <= skills.length.
  • -10^9 <= lowerBound <= upperBound <= 10^9.

More Wells Fargo problems

See Wells Fargo hiring insights
public long countValidTeams(int[] skills, int minPlayers, int lowerBound, int upperBound) {
  // write your code here
}
skills[1,2,3]
minPlayers2
lowerBound1
upperBound3
expected4
Checking account…