Allocate Wells for Fair Distribution
Updated
Problem statement
Oil wells stand around an island, in a circle. You are given the capacity of each well in order around the circle: A[i] is the capacity of well i, and well n - 1 is next to well 0. N companies bid for the wells.
Give the wells out so that each company gets a group of wells that sit next to each other (the group may wrap from the last well back to well 0). Every well goes to one company, and every company gets at least one well. A fair split is one that makes the difference between the largest and the smallest total capacity as small as possible.
Company 0 gets the group that contains well 0. The other companies follow in order around the circle. If more than one fair split exists, return the one whose list of totals is smallest when compared from the first company to the last.
Complete the function allocateWells in the editor.
allocateWells has the following parameters:
int[] A: the capacity of each wellint N: the number of companies
The function returns an int[] of length N: item i is the total capacity given 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]There are 8 wells and 4 companies. The fair split is:
- Company 0 gets wells 7 and 0 (the group wraps around the circle): 5 + 25 = 30.
- Company 1 gets wells 1 and 2: 13 + 17 = 30.
- Company 2 gets well 3: 40.
- Company 3 gets wells 4, 5 and 6: 8 + 9 + 22 = 39.
The difference between the largest and smallest total is 40 - 30 = 10. No split does better, so the answer is [30, 30, 40, 39].
Constraints
1 ≤ N ≤ n ≤ 20, wherenis the length ofA1 ≤ A[i] ≤ 100
More Wells Fargo interview questions
- Server Upgrade PlanningOA · Seen Nov 2026
- Student and Course EnrollmentOA · Seen Nov 2026
- Bond Interest Summary Above 3%OA · Seen Oct 2026
- Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
- Event Statistics AggregatorOA · Seen Sep 2026
- Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
- Longest Subsequence That Is a SubstringOA · Seen Jul 2026
- Overloaded Game Account InventoriesOA · Seen Jul 2026
- Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
- Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026
Similar questions at other companies
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
- Split Array Largest SumAuxoAI · OA
- Maximum Non-Decreasing Array LengthVisa · OAVisa interview questions
- Maximize Array Beauty After DeletionsPoint72 · OAPoint72 interview questions
- Min Elements to Remove to Make Almost Sorted ArraySalesforce · OASalesforce interview questions
- Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
- Fill a Time Window with SongsMicrosoft · OAMicrosoft interview questions
- Longest Increasing Subsequence from Two ArraysSquarepoint Capital · OASquarepoint Capital interview questions
- Split Array Largest SumLinkedIn · OALinkedIn interview questions
- Longest Increasing SubsequenceAtlassian · OAAtlassian interview questions