Problem · Array
Resource Allocation
Learn this problemProblem statement
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[]) → intExamples
Example 1
storageA = [1,2,0,4]storageB = [4,5,0,0,1]return = 12Replace 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^50 <= storageA[i], storageB[i] <= 10^4