Number of Ways to Wear Different Hats to Each Other
CodingPhone ScreenSoftware EngineerReported Nov, 2025
Examples
Example 1:
Input: hats = [[3,4],[4,5],[5]]
Output: 1
Example 2:
Input: hats = [[3,5,1],[3,5]]
Output: 4
Example 1:
Input: hats = [[3,4],[4,5],[5]]
Output: 1
Example 2:
Input: hats = [[3,5,1],[3,5]]
Output: 4
There are n people and 40 possible hat types. hats[i] lists the hats person i is willing to wear.
Return the number of valid assignments where every person gets exactly one hat they like and no two people wear the same hat, modulo 10^9 + 7.
1 <= hats.length <= 101 <= hats[i].length <= 401 <= hats[i][j] <= 40hats[i] contains distinct values.Reported as LeetCode 1434 in a software engineer phone screen.