Planning Production
Updated
Problem 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 Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
Similar questions at other companies
- Hiking Club Fastest PaceInfosys · OAInfosys interview questions
- Find Minimum TimeAlphaSense · OA
- Find Minimum TimeBlackRock · OABlackRock interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Minimum Cost of Every K-Capable Model SetTikTok · OATikTok interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions