Planning Production
Reported by candidates from Visa's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Visa reported this one in September 2026, and the detail that trips people is right in the example: you need 7 in hand to start product 2, but it only costs 1 to make. That gap between the worst-case requirement and the real spend is the whole problem. It's a greedy ordering question dressed up as a production plan. If you can see how to sort the products, the code is ten lines. If you blank on the sort key, StealthCoder is the invisible safety net that reads the problem and gives you the approach during the live OA.
The problem
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[]) → long Examples Example 1 worstCase = [6, 5, 7] expected = [4, 2, 1] return = 9 The optimal production order is 2, 1, 0: Start with 9 units of cash. Produce product 2: requires 7 units worst-case, spends 1 unit expected.Remaining cash: 9 - 1 = 8 units Produce product 1: requires 5 units worst-case, spends 2 units expected.Remaining cash: 8 - 2 = 6 units Produce product 0: requires 6 units worst-case, spends 4 units expected.Remaining cash: 6 - 4 = 2 units Therefore, the minimum starting amount is 9 units of cash.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is an exchange argument. Define the slack of a product as worstCase[i] minus expected[i]. Sort products by slack descending, so the ones that demand a lot of cash relative to what they burn go first, while you have the most money. Then simulate backward or forward. Forward: track the cash you need as the max over each product of (cost already spent before it + worstCase[i]). Spent-so-far is the prefix sum of expected values in sorted order. The answer is that max. Use long for sums, since the return type hints at overflow. The common pitfall is sorting by worstCase alone or by expected ascending, which fails on cases like the example. Check it: slacks are 2, 3, 6, so order is 2, 1, 0 and the max is 9. If you freeze live, StealthCoder can supply the sort key as a hedge.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Planning Production cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Visa's OA.
Visa reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Planning Production FAQ
What's the trick in Planning Production?+
Sort by worstCase minus expected, largest first. Products with a big gap between required cash and actual spend should run early. Then the answer is the max over products of prefix spend before it plus its worstCase. Sorting by worstCase alone gives wrong answers.
How hard is this problem really?+
Medium. The code is short, a sort and one loop. The difficulty is justifying the sort key. If you've seen the exchange-argument pattern for ordering tasks with a threshold and a cost, it's quick. If not, test small cases by hand.
Why does the example answer equal 9?+
Slacks are 2, 3, and 6 for products 0, 1, 2. Sorted descending the order is 2, 1, 0. Product 2 needs 7 with nothing spent. Product 1 needs 5 plus 1 spent, so 6. Product 0 needs 6 plus 3 spent, so 9. Max is 9.
Do I need long for this?+
Yes. The function returns long, so sums of expected values can exceed 32-bit int range with large inputs. Accumulate the prefix spend and the running max in long, and cast values before adding to avoid silent overflow.
How do I prepare in 48 hours for this Visa OA?+
Practice two or three greedy ordering problems where you sort by a derived key and prove it with an adjacent swap. Then write this one from scratch, check the example, and test edge cases like one product and equal slacks.