A Different Hat for Everyone
There are 40 hats, numbered 1 to 40, and likes[p] lists the hats person p is willing to wear. Give every person one hat they like, so that no two people get the same hat.
Return the number of ways to do this.
Example 1
likes [[1,2],[2,3]]
returns 3
The two people can wear hats 1 and 2, hats 1 and 3, or hats 2 and 3. Both taking hat 2 is not allowed.
Example 2
likes [[7],[7]]
returns 0
Both want the same single hat.
Constraints
1 <= len(likes) <= 81 <= len(likes[p]) <= 40- every hat is a number from 1 to 40, and no list names a hat twice
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.