Ctrl K

Ever-Growing Teams

Medium
Players are heading to a tournament, and scores[i] is the rating of player i. Split all players into non-empty teams and line the teams up so that each team is strictly larger than the one before it both in headcount and in the total rating. Every player belongs to exactly one team. Return the largest possible number of teams.
Example 1
scores=[4, 9, 2, 7, 5, 1, 8] → 3

For instance: team [1] with sum 1, team [2, 4] with sum 6 and team [5, 7, 8, 9] with sum 29. Four teams would need at least 1 + 2 + 3 + 4 = 10 people, but there are only 7.

Example 2
scores=[6, 6] → 1

Two one-person teams are not allowed, since sizes must strictly grow, so both people form a single team.

Example 3
scores=[3] → 1
Constraints
  • 1 ≤ len(scores) ≤ 10⁵
  • 1 ≤ scores[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrices That Fade With Each Sale MediumShave Primes Into Order MediumLevel Out to a Palindrome MediumA Crew Levels a Hill MediumGrowing Groups Without Repeats Hard
loading Python…
Input
scores=[4, 9, 2, 7, 5, 1, 8]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.