Problem Brief
Compute Least Truck Count
FULLTIMEOA
See Amazon online assessment and hiring insights
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.
1Example 1
Input
items = [2, 4], capacity = 3, max_same_type_limit = 2
Output
2
Explanation
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
2Example 2
Input
items = [4, 4, 3], capacity = 3, max_same_type_limit = 3
Output
4
Explanation
no source so far..Will update once find it..