Problem · Greedy
Planning Production
Learn this problemProblem statement
You must plan production for a company that manufactures multiple products. For each product i:
worstCase[i]is the minimum cash that must be available before production begins.expected[i]is the cost actually spent during production.
Determine the minimum amount of starting cash needed to manufacture all products. Products can be produced in any order, and after completing each product, the remaining cash can be used for subsequent products.
Function
plenProduction(worstCase: int[], expected: int[]) → longExamples
Example 1
worstCase = [6, 5, 7]expected = [4, 2, 1]return = 9The optimal production order is 2, 1, 0:
- Start with
9units of cash. - Produce product
2: requires7units worst-case, spends1unit expected.- Remaining cash:
9 - 1 = 8units
- Remaining cash:
- Produce product
1: requires5units worst-case, spends2units expected.- Remaining cash:
8 - 2 = 6units
- Remaining cash:
- Produce product
0: requires6units worst-case, spends4units expected.- Remaining cash:
6 - 4 = 2units
- Remaining cash:
Therefore, the minimum starting amount is 9 units of cash.
More Visa problems
- Minimum Cost to Attend Required CoursesOA · Seen Jul 2026
- Minimum Score of a Path Between CitiesOA · Seen Jul 2026
- Subarray SumOA · Seen Jul 2026
- Maximum Even Tag SumOA · Seen Jun 2026
- Transform Binary MatrixOA · Seen Jun 2026
- Minimum Cost to Select People for Skill QuotasOA · Seen May 2026
- Longest Selectable Non-Decreasing SubarrayOA · Seen Apr 2026
- Maximize Capped Contribution SumOA · Seen Apr 2026