Maximum Number of Groups With Increasing Length
Real-world version: How Many Growing Batches Can Be FilledThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def max_increasing_groups(stock: list[int]) -> int:public int maxIncreasingGroups(int[] stock)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Sell Diminishing-Valued Colored BallsReal-world version: Rare Poster RevenueMedium
- Missing NumberReal-world version: Unclaimed Badge NumberEasy
- Earliest Finish Time for Land and Water Rides IReal-world version: Forge and Kiln BookingEasy
- Longest Subsequence With Limited SumReal-world version: Parcels Within Each AllowanceEasy