Maximize Merchant Deal Portfolio Value
As a leading fintech platform, Phonepe constantly innovates to provide value to both its users and merchant partners. A critical aspect involves curating attractive deal portfolios for merchants, balancing potential revenue gains with associated costs. This problem challenges you to optimize the selection of merchant deals within a defined budget to maximize the overall value generated.
Your task is to implement a function that, given a list of potential merchant deals (each with an associated value and cost) and a maximum budget, determines the maximum total value that can be achieved by selecting a subset of these deals. Each deal can be chosen at most once.
Function Signature:
function maximizeDealPortfolioValue(dealValues: number[], dealCosts: number[], budget: number): number
dealValues: An array of positive integers, where dealValues[i] represents the monetary or strategic value gained from selecting the i-th deal.dealCosts: An array of positive integers, where dealCosts[i] represents the financial cost incurred for selecting the i-th deal. dealCosts will have the same length as dealValues.budget: A positive integer representing the maximum total cost Phonepe can afford for the selected deals.Return Value:
Return a single integer: the maximum total value that can be achieved without exceeding the budget. If no deals can be selected within the budget, return 0.
dealValues and dealCosts will not be empty. Their length will be at least 1.budget is 0, no deals can be selected unless a deal has a cost of 0 (which is not allowed by constraints). In such cases, the result should be 0.dealValues, dealCosts, budget) are positive integers.Examples
Example 1
Input:
dealValues = [60, 100, 120], dealCosts = [10, 20, 30], budget = 50
Output:
220
Note:
To maximize value, select the deal with value 100 (cost 20) and the deal with value 120 (cost 30). Total value = 100 + 120 = 220. Total cost = 20 + 30 = 50. This fits exactly within the budget. Other combinations, such as selecting all three deals, would exceed the budget.
Example 2
Input:
dealValues = [10, 20, 30], dealCosts = [60, 70, 80], budget = 50
Output:
0
Note:
No single deal can be selected as all deals have a cost greater than the budget of 50. Therefore, the maximum achievable value is 0.
Example 3
Input:
dealValues = [10, 20, 30, 40], dealCosts = [5, 10, 15, 20], budget = 25
Output:
50
Note:
Several combinations achieve a value of 50 within the budget:
Constraints
1 <= dealValues.length == dealCosts.length <= 1001 <= dealValues[i], dealCosts[i] <= 10001 <= budget <= 10000Loading editor...