Problem · Array

Resource Allocation

Learn this problem
MediumMaven Securities logoMaven SecuritiesINTERNOA

Problem 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[]) → 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

More Maven Securities problems

drafts saved locally
public int minimumResources(int[] storageA, int[] storageB) {
    // Write your code here
}
storageA[1,2,0,4]
storageB[4,5,0,0,1]
expected12
checking account