Problem · Array
Balancing Teams
Learn this problemProblem 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[]) → intExamples
Example 1
teamA = [5, 10, 0, 4]teamB = [2, 4, 0, 5, 0]return = 20Fill 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
- Beautiful ArrangementONSITE INTERVIEW · Seen Jul 2026
- Find Minimum Cost to Remove Array ElementsONSITE INTERVIEW · Seen Jul 2026
- Group Shifted StringsONSITE INTERVIEW · Seen Jul 2026
- Longest Valid ParenthesesONSITE INTERVIEW · Seen Jul 2026
- Largest Sub-GridOA · Seen Nov 2025
- Discount TagsOA · Seen Oct 2024
- Odd One OutOA · Seen Oct 2024
- Alloy ProductionOA · Seen Sep 2024