Problem · Array

Minimum Team Size From Every Start

Learn this problem
MediumAtlassian logoAtlassianFULLTIMEOA

Problem statement

Students stand in a fixed order. talent[i] is an integer from 1 through talentsCount.

For every starting index, choose a consecutive group beginning there that contains every talent at least once. Return the minimum possible group length for each start, or -1 when the remaining suffix cannot form a complete team.

Function

teamSize(talent: int[], talentsCount: int) → int[]

Examples

Example 1

talent = [1,2,3,2,1]talentsCount = 3return = [3,4,3,-1,-1]

The shortest complete windows starting at the first three positions have lengths 3, 4, and 3. The last two suffixes miss at least one talent.

Constraints

  • 1 <= talent.length, talentsCount <= 200000
  • 1 <= talent[i] <= talentsCount

More Atlassian problems

drafts saved locally
public int[] teamSize(int[] talent, int talentsCount) {
  // Write your code here.
}
talent[1,2,3,2,1]
talentsCount3
expected[3,4,3,-1,-1]
checking account