I came across this problem in a coding test. My solution gave few WA and TLE in some test cases…

You are given X different type of candies represented by 1, 2, 3… X. There are N people each having a list of their favorite candies. You need to find number of ways to distribute these candies such that:

- Each person gets exactly one candy from their list of favorite candies.
- No two person have same type of candy.

X<= 200, N<=10 and sizeoffavoritelist of each person <= X.

For this problem, I wrote a recursive function, in which for each person it had choice of taking any unvisited candy. But, somehow it gave some WA and TLE. Can someone provide some test cases or correct approach?