Sponsored
Use these hints if you're stuck. Try solving on your own first.
Dynamic programming + bitmask.
dp(peopleMask, idHat) number of ways to wear different hats given a bitmask (people visited) and used hats from 1 to idHat-1.
Solve with full IDE support and test cases