Resource Allocation
Updated
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[]) → 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
More Maven Securities Online Assessment questions
Similar questions at other companies
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Values with Even Powers of TwoVisa · OAVisa interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMicrosoft · OAMicrosoft interview questions
- Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimum Total Batch ExpenseAmazon · OA
- Coprime Pick with Change CostCitadel · OACitadel interview questions
- Minimum Increments for Stepwise TowersZipRecruiter · OAZipRecruiter interview questions