142. Partition a Replay Into Valid Batches
HardDynamic programming
Replay records must stay in order. Partition their sizes into contiguous, nonempty batches, each with total size between minimum and maximum inclusive.
Return the fewest valid batches, 0 for an empty stream, or -1 if no partition can cover every record.
Example 1
Input: sizes = [2,2,3,2], minimum = 4, maximum = 7 Output: 2
Example 2
Input: sizes = [2,2,2,2,2], minimum = 4, maximum = 6 Output: 2
Constraints
At most 100,000 records. Every size is an integer in [1, 10⁶].1 ≤ minimum ≤ maximum ≤ 10¹¹. Aim for linear time.