Ctrl K

Growing Groups Without Repeats

Hard
You are given an array limits of length n. Build several groups out of the numbers 0 to n - 1 so that: - no number repeats inside a group; - every group is strictly longer than the one before it; - number i appears at most limits[i] times across all groups. Return the largest number of groups you can build.
Example 1
limits=[3, 1, 2] → 3

Groups [0], [0, 2], [0, 1, 2]: number 0 is used three times, 1 once and 2 twice, and the sizes grow 1 → 2 → 3.

Example 2
limits=[1, 1, 1, 1] → 2

Each number is available once, so for example [0] and [1, 2] work. Only number 3 remains for a third group, which would need three numbers.

Example 3
limits=[6] → 1
Constraints
  • 1 ≤ len(limits) ≤ 10⁵
  • 1 ≤ limits[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 MediumLevel Out to a Palindrome MediumBiggest Number Divisible by Three HardLifters and Energy Drinks HardKeep Every Lamp Running Hard
loading Python…
Input
limits=[3, 1, 2]
Expected
3

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