Minimize Total Input Cost (for LTMS)
Updated
Problem statement
Given an array of campaign costs and a number of weeks, partition the campaigns to minimize the sum of weekly maximum costs.
Campaigns must be executed in the order they appear, and each week must contain at least one campaign. The input cost for a week is the maximum campaign cost assigned to that week.
Return the minimum possible sum of weekly maximum costs.
Function
minimizeTotalInputCost(campaignCosts: int[], numberOfWeeks: int) → int Complete the function minimizeTotalInputCost in the editor.
minimizeTotalInputCost has the following parameters:
int[] campaignCosts: an array of integers representing the campaign costsint numberOfWeeks: the number of weeks
Returns int: the minimized total input cost
Examples
Example 1
campaignCosts = [1000, 500, 2000, 8000, 1500]numberOfWeeks = 3return = 9500Optimal 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:
1000 + 500 + 8000 = 9500
The sum of all weekly maximum costs is minimized, so the answer is 9500.
Example 2
campaignCosts = [2, 5, 4, 3, 7, 1, 6, 8]numberOfWeeks = 3return = 15One optimal partition is:
[2], weekly maximum =2[5, 4, 3], weekly maximum =5[7, 1, 6, 8], weekly maximum =8
So the minimized total is 2 + 5 + 8 = 15.
Note: This example was added on June 21, 2026 from a newly reported Salesforce onsite question variant. 🍓
Constraints
campaignCostsis a non-empty array.1 <= numberOfWeeks <= campaignCosts.length- The campaign order must be preserved.
More Salesforce interview questions
- Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
- Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
- 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
- Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays With Product Equal to KOA · Seen Nov 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
- Get Message StatusOA · Seen Nov 2026
- Detect a Cycle in a Linked ListPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Maximum Even-Sum Neighboring PairsDRW · OADRW interview questions
- Maximize Protected City PopulationAmazon · OA
- Network FormationPalantir · OAPalantir interview questions
- Maximum Even Subsequence SumExpedia · OAExpedia interview questions
- Maximum Even-Sum Adjacent Pairs in a Circular ArrayTesla · OATesla interview questions
- Fewest Fountains to Water the GardenDocuSign · OADocuSign interview questions
- Minimum Jumps to Reach the EndNutanix · OANutanix interview questions
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
- Split Array Largest SumAuxoAI · OA
- Maximum Income from Asset TradingJefferies · OA