There are n unique categories of goods. You are given an array inventory of length n, where inventory[i] denotes the count of items available for category i (with i ranging from 0 to n - 1). These goods need to be organized into groups for delivery.
Group Packing Conditions:
Goal:
Examples
01 · Example 1
inventory = [2, 3, 1, 4, 2] return = 4
The initial bundle holds 1 unit from type 4. Leftover stock: [2, 3, 1, 4, 1]
The second bundle packs 2 units from types 0 and 1. Remaining stock: [1, 2, 1, 4, 1]
The third bundle consists of 3 units from types 0, 1, and 3. Remaining stock: [0, 1, 3, 1]
The fourth bundle carries 4 units from types 1, 2, 3, and 4. Remaining stock: [0, 0, 0, 2, 0]
So we get 4 as our expected output :)
More Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int maxBatchesForShipment(int inventory[]) {
// write your code here
}
inventory[2, 3, 1, 4, 2]
expected4
sign in to submit