FunctionRacerProblemsRace

A Different Hat for Everyone

HardBitsPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems