FastPrepBalancing Teams
Problems/Balancing Teams

Balancing Teams

MathWorks logoMathWorks● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

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.

Function

equalTeamSkill(teamA: int[], teamB: int[]) → int

Examples

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^5
  • 0 <= teamA[i], teamB[i] <= 10^4

More MathWorks problems

  • Earliest Time to Schedule a MeetingOA · Seen Nov 2026
  • Minimum Cost to Serve Requests on a RingOA · Seen Nov 2026
  • Minimum Tree Diameter After Removing K LeavesOA · Seen Nov 2026
All MathWorks interview questionsSee MathWorks hiring insights
Saved
class Solution {
    public int equalTeamSkill(int[] teamA, int[] teamB) {
      // write your code here
    }

}
Checking account…