Delivery Partner Earnings Maximizer
As a Swiggy delivery partner, optimizing your time and earnings is crucial. Imagine you've arrived at a restaurant, and there are multiple ready-to-pickup orders. Each order has a specific preparation time (even if ready, there's a small handover/packaging time) and an associated earning (delivery fee + potential tip). You have a limited amount of time you can afford to spend at this particular restaurant before it impacts your overall delivery schedule. Additionally, your delivery bag has a limited capacity, meaning you can only carry a certain number of orders at once. Your goal is to select a subset of available orders to maximize your total earnings while respecting both the maximum wait time and the maximum number of orders you can carry.
Implement a function maximizeEarnings that takes the following parameters:
prepTimes: An array of integers where prepTimes[i] is the time (in minutes) required for the i-th order.earnings: An array of integers where earnings[i] is the earning (in rupees) for the i-th order.maxWaitTime: An integer representing the maximum total time (in minutes) you can spend at the restaurant.maxOrdersToCarry: An integer representing the maximum number of orders you can pick up.The function should return the maximum total earnings achievable.
Function Signature:
function maximizeEarnings(prepTimes: number[], earnings: number[], maxWaitTime: number, maxOrdersToCarry: number): number
Parameters:
prepTimes: An array of N positive integers representing the preparation/handover time for each order.earnings: An array of N positive integers representing the earnings for each order.maxWaitTime: A positive integer representing the maximum total time budget.maxOrdersToCarry: A positive integer representing the maximum number of orders that can be picked up.Return Value:
0.prepTimes and earnings arrays will always have the same length, N.Examples
Example 1
Input:
prepTimes = [10, 20, 30], earnings = [60, 100, 120], maxWaitTime = 50, maxOrdersToCarry = 2
Output:
220
Note:
To maximize earnings, pick orders with (time=20, earn=100) and (time=30, earn=120). Total time = 50 (<= maxWaitTime), total orders = 2 (<= maxOrdersToCarry). Total earnings = 220.
Example 2
Input:
prepTimes = [5, 5, 5], earnings = [10, 20, 30], maxWaitTime = 10, maxOrdersToCarry = 1
Output:
30
Note:
With maxOrdersToCarry = 1, you can only pick one order. The order with (time=5, earn=30) yields the highest earnings while respecting maxWaitTime.
Example 3
Input:
prepTimes = [100, 150], earnings = [200, 300], maxWaitTime = 50, maxOrdersToCarry = 1
Output:
0
Note:
Neither order can be picked as their individual preparation times (100 and 150) exceed the maxWaitTime of 50. No orders can be picked, so earnings are 0.
Constraints
1 <= N <= 200 (where N is the number of available orders)1 <= prepTimes[i] <= 100 for all i1 <= earnings[i] <= 500 for all i1 <= maxWaitTime <= 20001 <= maxOrdersToCarry <= NmaxOrdersToCarry <= 20N is extremely large (e.g., millions of orders).Loading editor...