Amazon handles the shipment of millions of packages worldwide daily. At one of their facilities, there are m distinct product categories scheduled for shipment. The count of parcels for product type i is represented by items[i].
Each delivery truck comes with a fixed load limit, defined by capacity, and there’s an additional restriction that no more than max_same_type_limit parcels of any single product type can be loaded onto a truck.
Your task is to compute the minimum number of trucks required to transport all the parcels while adhering to both the truck capacity and product-specific constraints.
Examples
01 · Example 1
items = [2, 4] capacity = 3 max_same_type_limit = 2 return = 2
There are n = 2 product types. The parcel counts are items = [2, 4].
Each truck can carry up to 3 parcels total, but no more than 2 of any specific product type per truck.
Our loading Strategy:
Truck 1: Load 1 parcel of type 1 and 2 parcels of type 2. Total = 3 (within capacity)
Truck 2: Load 1 parcel of type 1 and 2 parcels of type 2. Total = 3 (within capacity)
Note: Loading 3 parcels of type 2 into one truck is invalid since max_same_type_limit = 2.
Therefore, all parcels are shipped in 2 trucks without breaking any conditions.
Final Answer: 2
02 · Example 2
items = [4, 4, 3] capacity = 3 max_same_type_limit = 3 return = 4
no source so far..Will update once find it..
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 getMinimumNumberOfTrucks(int[] items, int capacity, int max_same_type_limit) {
// write your code here
}
items[2, 4]
capacity3
max_same_type_limit2
expected2
sign in to submit