Problem · Array
Balancing Teams
Two teams have skill arrays teamA and teamB. A value of 0 means that player slot is empty.
Fill every empty slot with a positive skill value no larger than 10000 so that both teams end with the same total skill. Return the minimum possible equal team sum, or -1 if no such assignment exists.
Examples
01 · Example 1
teamA = [5, 10, 0, 4] teamB = [2, 4, 0, 5, 0] return = 20
Fill the zero in teamA with 1, and the zeros in teamB with 3 and 6. Both teams then sum to 20, which is the minimum equal sum.
Constraints
1 <= n, m <= 10^50 <= teamA[i], teamB[i] <= 10^4
More MathWorks problems
public int equalTeamSkill(int[] teamA, int[] teamB) {
// write your code here
}
teamA[5, 10, 0, 4]
teamB[2, 4, 0, 5, 0]
expected20
sign in to submit