Ctrl K

Distinct Badges for the Team

Hard
A team of n people is going to a conference. The organisers print badges in 40 colours numbered from 1 to 40, and each colour can go to one person only. likes[i] is the list of colours the i-th person is willing to wear. Count the ways to give every person exactly one badge so that each gets a colour from their own list and no two people get the same colour. Two ways differ if at least one person gets a different colour. The answer can be large, so return it modulo 10⁹ + 7.
Example 1
likes=[[2, 7], [7], [1, 2]] → 1

The second person must get 7, so the first gets 2 and the third is left with 1. There is one way.

Example 2
likes=[[5, 6], [5, 6, 9]] → 4

The pairs (5, 6), (5, 9), (6, 5) and (6, 9): 4 ways.

Example 3
likes=[[3], [3], [1, 2]] → 0

The first two both accept only colour 3, and nobody may share a badge.

Constraints
  • n = len(likes)
  • 1 ≤ n ≤ 10
  • 1 ≤ len(likes[i]) ≤ 40
  • 1 ≤ likes[i][j] ≤ 40
  • No colour repeats within one list likes[i]
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSettle Up in the Fewest Transfers HardTwo Groups With the Same Average HardAssembling Fragments HardSquare-Sum Chains HardSmallest Team With Every Skill Hard
loading Python…
Input
likes=[[2, 7], [7], [1, 2]]
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.