Planning Production
Updated
Problem statement
Acme Corp has a number of products that need to be manufactured. However, careful planning must take place before production begins. For each product there is a worst-case cost and an expected cost. Before starting a project, Acme must have at least enough cash on hand to pay the worst-case cost for each product. If every product is produced at expected cost, determine the minimum beginning cash requirement to get all products produced. Products can be produced in any order.
Function
planProduction(worstCase: int[], expected: int[]) → int
Complete the function planProduction in the editor.
planProduction has the following parameter(s):
worstCase[worstCase[0],...worstCase[n-1]]: an array ofnintegers representing the minimum cash-on-hand to produce theith productexpected[expected[0],...expected[n-1]]: an array ofnintegers, representing the expected cost to produce theith product.
Returns int: the minimum beginning cash requirement to get all products produced
Examples
Example 1
worstCase = [6, 5, 7]expected = [4, 2, 1]return = 9For this case, the optimal order of production is product 2, 1, and 0. Starting with 9 units of cash on hand, they can begin production of product 2 because cash on hand (9 units) ≥ worstCase (7 units). After finishing product 2, they will have 9 - 1 = 8 units of cash on hand. They can then move to product 1 as cash on hand (8 units) ≥ worstCase (5 units). When product 1 is complete, they will have 8 - 2 = 6 units of cash on hand which is enough to start product 0 as cash on hand (6 units) = worstCase (6 units). The minimum amount of cash on hand that will work is 6 - 4 = 2 units. The answer is 9.
Constraints
1 ≤ n ≤ 10^51 ≤ worstCase[i] ≤ 10^51 ≤ expected[i] ≤ 10^5- It is guaranteed that
expected[i] ≤ worstCase[i]for everyi(0 ≤i<n).
More Atlassian interview questions
- Merge Overlapping IntervalsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Tennis Court SchedulingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Deterministic Word Guess SolverONSITE INTERVIEW · Seen Oct 2026
- Generate Word Guess FeedbackONSITE INTERVIEW · Seen Oct 2026
- Bounded Word Guess SolverONSITE INTERVIEW · Seen Oct 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Word Guess Feedback ColorsONSITE INTERVIEW · Seen Oct 2026
- Longest Consistent Activity StreakPHONE SCREEN · Seen Sep 2026
- Music Player Operation SequencePHONE SCREEN · Seen Sep 2026
- Underline Shortest Unique SubstringsPHONE SCREEN · Seen Aug 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