Problem 551597 · hard · Level 05 Advanced Algorithms & Graphs

Split Players Into Equal-Strength Teams

backtracking · partitioning · pruning · symmetry

A coach has players with skill ratings skills and wants exactly k teams whose total skills are all equal. Every player must join exactly one team; teams may have different sizes. Return True if this is possible, otherwise False.

Examples

Input:  skills = [5, 1, 4, 2, 3, 3], k = 3
Output: True
Explanation: {5, 1}, {4, 2}, {3, 3} each total 6.

Input:  skills = [2, 2, 2, 3], k = 2
Output: False
Explanation: the total 9 cannot be split in half.

Input:  skills = [7], k = 1
Output: True

Constraints

  • 1 <= len(skills) <= 14, 1 <= skills[i] <= 100, 1 <= k <= 8

Goals

  • Assign items to buckets with a capacity and backtrack on failure
  • Break symmetry so equivalent bucket choices are tried only once
Starting Python…