Resource Allocation
Reported by candidates from Maven Securities's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Maven Securities reportedly served this one up in August 2026, and it looks easy until one row has no zeros. Two rows of storage units, zeros are empty, and you fill each zero with a positive integer so both row sums match at the lowest total possible. It's a greedy sum problem wearing a costume. If you've got the OA in a day or two, the whole thing comes down to one minimum and one edge case. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you can learn this in five minutes.
The problem
There are two rows of storage units, storageA and storageB. Each unit contains a nonnegative number of resources, and 0 marks an empty unit. Replace every 0 in both rows with a strictly positive integer so that the two row sums become equal. Return the minimum equal total that can be achieved, or -1 if no such allocation is possible. Function minimumResources(storageA: int[], storageB: int[]) → int Examples Example 1 storageA = [1,2,0,4] storageB = [4,5,0,0,1] return = 12 Replace the zero in storageA with 5, producing [1,2,5,4]. Replace the two zeros in storageB with 1 each, producing [4,5,1,1,1]. Both rows then sum to 12, which is the minimum possible equal total. Constraints 1 <= storageA.length, storageB.length <= 10^5 0 <= storageA[i], storageB[i] <= 10^4
Reported by candidates. Source: FastPrep
Pattern and pitfall
Compute each row's sum with zeros counted as 1, since every zero must become at least 1. Call these minA and minB. The answer is max(minA, minB), unless the smaller side is stuck. That's the pitfall. If a row has no zeros, its sum is fixed and can't grow. So if the row with the smaller minimum has zero zeros, return -1. Otherwise the row with zeros can absorb the difference by inflating one zero. Walk through Example 1: A becomes 1+2+1+4 = 8, B becomes 4+5+1+1+1 = 12, so the answer is 12, and A has a zero to stretch. Naive solutions forget the fixed-row check or use plain sums without the 1 floor. It's one pass, O(n) time, O(1) space. Use a 64-bit-safe mindset, though sums stay near 10^9. If you freeze on the live OA, StealthCoder can hand you this logic while you type.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Resource Allocation 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as minimum equal sum of two arrays after replacing zeros. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Maven Securities's OA.
Maven Securities reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Resource Allocation FAQ
What's the trick in Maven Securities' Resource Allocation problem?+
Treat every zero as 1 to get each row's minimum possible sum. The target is the larger of the two minimums. Then check whether the row with the smaller minimum has any zeros to stretch. If it doesn't, the answer is -1.
When exactly do you return -1?+
When the row with the smaller minimum sum contains no zeros. Its total is locked, so it can't rise to match the other row. Also if both rows have no zeros and their sums differ, that's -1 too. Equal fixed sums just return that sum.
How hard is this really?+
Easy to medium. The code is about ten lines and runs in one pass. The difficulty is purely the edge case where a row can't grow. If you reason about which row is flexible, it falls out quickly.
Do I need a fancy data structure or algorithm?+
No. You only need two running sums and two zero counts. No sorting, no hash map, no dynamic programming. It's a greedy and counting problem, O(n) time and O(1) extra space with arrays up to 10^5 long.
How do I prepare for this in 48 hours?+
Write the solution from scratch twice. Test it on cases with no zeros in either row, zeros only in the lower row, and zeros only in the higher row. Then run the sample, which should give 12. That covers nearly every failure mode.