Minimum batches
You are given a list of item sizes and a batch limit. Split the list into the fewest possible batches of consecutive items, keeping the original order, such that no batch's total size exceeds the limit. Every individual size is at most the limit. Return the number of batches. Example: sizes [4, 4, 3, 6] with limit 8 needs 3 batches: [4, 4], [3], [6].
Implement
min_batches(sizes: list[int], limit: int) → intExamples
in
[[4,4,3,6],8]out3What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 11 min
solution.py
InputExpectedGot
[[4,4,3,6],8]3not run yetsample