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 players
  • k: 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
INPUTALGORITHMRESULTPlayers: [8,2,6,4,1,9], k=3826419Need 3 balanced teamsMinimize skill difference1Sort PlayersDescending: [9,8,6,4,2,1]2Snake DraftRound 1: A→B→CRound 2: C→B→A3Assign Players9→A, 8→B, 6→C4→C, 2→B, 1→A4Balance CheckTeams naturally balancedTeam A[9,1]Team B[8,2]Team C[6,4]Total: 10Total: 10Total: 10Perfect Balance!Difference: 0Key Insight:Snake draft pattern (like sports drafts) automatically creates balanced teams by alternatingdistribution direction each round, eliminating the need for complex optimization calculations.TutorialsPoint - Team Formation Splitter | Greedy Snake Draft
Asked in
Google 12 Amazon 8 Microsoft 6 Meta 4
23.4K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen