All problems
1041HardArrayMathBinary SearchGreedySorting

How Many Growing Batches Can Be Filled

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2790Maximum Number of Groups With Increasing Length

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A store holds parts of several kinds, and stock[i] is how many parts of kind i it holds.

Fill a run of batches so that no batch holds two parts of the same kind, no kind is drawn on more times across all the batches than the store holds, and each batch after the first holds strictly more parts than the one before it.

Return the greatest number of batches that can be filled.

Examples

Example 1

Input
stock = [5, 2, 1]
Output
3

Three batches need one, two and three parts, six in all. The batch of three takes one part of each kind, the batch of two takes one of the first kind and one of the second, and the batch of one takes another of the first kind. A fourth batch would need four different kinds and only three exist.

Example 2

Input
stock = [3, 3]
Output
2

Only two kinds exist, so no batch can hold three parts without repeating a kind, which caps the run at a batch of one and a batch of two.

Example 3

Input
stock = [1000000000]
Output
1

One kind means no batch can hold two parts, so a single batch of one part is all there is, however many parts the store holds.

Constraints

  • 1 <= stock.length <= 10^5
  • 1 <= stock[i] <= 10^9

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def max_increasing_groups(stock: list[int]) -> int:
Java
public int maxIncreasingGroups(int[] stock)
September 7
Apply