Problem · Array
Compute Least Truck Count
Learn this problemProblem statement
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.
Function
getMinimumNumberOfTrucks(items: int[], capacity: int, max_same_type_limit: int) → intExamples
Example 1
items = [2, 4]capacity = 3max_same_type_limit = 2return = 2There 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
Example 2
items = [4, 4, 3]capacity = 3max_same_type_limit = 3return = 4no source so far..Will update once find it..
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026