Find Minimum Trips π
Learn this problemProblem statement
There were a large number of orders placed on Amazon Prime Day. The orders are packed and are at the warehouse ready to be delivered. The delivery agent needs to deliver them in as few trips as possible.
In a single trip, the delivery agent can choose packages following either of two rules:
Determine the minimum number of trips required to deliver the packages. If it is not possible to deliver all of them, return -1.
Function
findMinTrips(packageweight: int[]) β int
Complete the function findMinTrips in the editor.
findMinTrips has the following parameter:
int packageweight[n]: the weights of each package
Returns
int: the minimum number of trips required or -1 if it is not possible to deliver them all
π π π π° Credit to Jane π° π π π
Examples
Example 1
packageweight = [1, 8, 5, 8, 5, 1, 1]return = 3
Example 2
packageweight = [3, 4, 4, 3, 1]return = -1Example 3
packageweight = [2, 4, 6, 6, 4, 2, 4]return = 3
Constraints
1 β€ n β€ 10551 β€ packageweight[i] β€ 109More 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