Campaigns should be executed in the order they appear. Each week must contain at least one campaign. Weekly input cost is equal to the maximum cost of any campaign in that week. The goal is to minimize the total input cost, which is the sum of weekly input costs.
Complete the function minimizeTotalInputCost in the editor.
minimizeTotalInputCost has the following parameters:
- 1.
int[] campaignCosts: an array of integers representing the costs of campaigns - 2.
int numberOfWeeks: the number of weeks
Returns
int: the minimized total input cost
Examples
01 · Example 1
campaignCosts = [1000, 500, 2000, 8000, 1500] numberOfWeeks = 3 return = 9500
The input might not be right...But it looks correct somehow...
Optimal Allocation:
- Week 1: {1000} → Max Cost = 1000
- Week 2: {500} → Max Cost = 500
- Week 3: {2000, 8000, 1500} → Max Cost = 8000
Output:
- Weekly Input Costs: {1000, 500, 8000}
- Total Input Cost (TIC): 1000 + 500 + 8000 = 9500
Explanation:
- Minimized Weekly Input: The maximum cost in any week is minimized.
- Optimal Total Input Cost: The sum of all weekly maximum costs (9500) is the smallest possible.
More Salesforce problems
- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
- Collect Opportunity Data in a TreeOA · Seen Feb 2026
- Replace '?' to Avoid Adjacent DuplicatesOA · Seen Feb 2026
- Strings With No k Consecutive Identical CharactersOA · Seen Feb 2026
- Spam ClassificationSeen Jun 2025
public int minimizeTotalInputCost(int[] campaignCosts, int numberOfWeeks) {
// write your code here
}
campaignCosts[1000, 500, 2000, 8000, 1500]
numberOfWeeks3
expected9500
sign in to submit