Problem · Array

Allocate Wells for Fair Distribution

Learn this problem
HardWells FargoOA

Problem statement

There are Oil wells around an island, represented as an array A[] where A[i] is the capacity of well i. There are N companies who bid for these wells. Now each company has to be allocated wells in a contiguous manner with fair distribution. A fair distribution is one which minimises the difference of the sum of capacity allocated to each of the companies.

Input array A[] of length n

Output capacity[] of length N where capacity[i] represents the total capacity allocated to company i.

Function

allocateWells(A: int[], N: int) → int[]

Examples

Example 1

A = [25, 13, 17, 40, 8, 9, 22, 5]N = 4return = [30, 30, 40, 39]
The wells are allocated as follows:
  • capacity[0] = A[0] + A[7] = 30 ; Contiguous as circular array
  • capacity[1] = A[1] + A[2] = 30
  • capacity[2] = A[3] = 40
  • capacity[3] = A[4] + A[5] + A[6] = 39
The difference between the minimum and maximum capacity[i] = 40 - 30 = 10.

Constraints

🦔

More Wells Fargo problems

drafts saved locally
public int[] allocateWells(int[] A, int N) {
  // write your code here
}
A[25, 13, 17, 40, 8, 9, 22, 5]
N4
expected[30, 30, 40, 39]
checking account