Team Formation Splitter - Problem
You are organizing a sports tournament and need to divide N players into K teams of equal size. Each player has a skill level represented by an integer.
Your goal is to create teams such that the difference between the highest and lowest total skill sums across all teams is minimized. This ensures the most balanced competition possible.
Input:
players: Array of integers representing skill levels of N playersk: Number of teams to form
Output:
Return a 2D array where each sub-array represents one team (containing player skill levels). The teams should be arranged to minimize the difference between team totals.
Constraints:
- N is divisible by K (equal team sizes guaranteed)
- Each team must have exactly N/K players
Input & Output
Example 1 — Basic Team Split
$
Input:
players = [8, 2, 6, 4, 1, 9], k = 3
›
Output:
[[9,1],[8,2],[6,4]]
💡 Note:
Sorted: [9,8,6,4,2,1]. Snake draft: Team 1 gets 9,4 (total 13), Team 2 gets 8,2 (total 10), Team 3 gets 6,1 (total 7). Difference: 13-7=6.
Example 2 — Perfect Balance Possible
$
Input:
players = [10, 8, 6, 4, 2, 0], k = 2
›
Output:
[[10,2,0],[8,6,4]]
💡 Note:
Both teams get total 12. Snake distribution: Team 1: [10,6,2], Team 2: [8,4,0], both sum to 18. Actually [10,2,0] and [8,6,4] both sum to 12 for perfect balance.
Example 3 — Four Teams
$
Input:
players = [9, 7, 5, 3, 8, 6, 4, 2], k = 4
›
Output:
[[9,3],[8,2],[7,4],[6,5]]
💡 Note:
Sorted: [9,8,7,6,5,4,3,2]. Snake pattern distributes evenly across 4 teams, each getting 2 players.
Constraints
- 2 ≤ players.length ≤ 1000
- players.length % k == 0
- 1 ≤ k ≤ players.length
- -1000 ≤ players[i] ≤ 1000
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code