Bowl $1$ contains $N_1$ candies, all different from each other. Bowl $2$ contains $N_2$ candies, all different from each other. However there are $p$ candies identical across the two bowls.
In other words, the first bowl contains $p$ candies identical to as many candies in the second bowl and $N_1 - p$ candies that have no equivalent in the second bowl. Similarly, the second bowl contains $p$ candies that are identical to as many candies in the first bowl, and $N_2 - p$ candies that have no equivalent in the first bowl.
Now suppose I draw $m_1$ random candies from the first bowl and $m_2$ from the second one. What is the mean number of candy pairs that I will be drawing?
In other words, how many of those $m_1$ candies I draw will be identical to some candies I'm drawing from the second bowl? Or equivalently, how many of the $m_2$ candies I have drawn from the second bowl will be identical to some of the $m_1$ candies I have drawn from the first bowl?
Choices for $\displaystyle m_1 = \sum_{k = 0}^p \binom {p}{k} (2^{N_1-p}-1) \ \ $, considering the fact $m_1, m_2> 0 $ and then if choices for $m_2$ are :
$\displaystyle m_2 = \sum_{k = 0}^p (2^{N_2-k}-1) \ \ $ wil have eactly $k$ number of identical candies.
I have considered that, there are identical candies in $ m_1$ and $m_2$ but if there are no identical candies, then the choices would be a litlle different. What I have done is the divided the set $m_1$ in two parts, one having atleat one elment of $p$ , and other having none (for $ k = 0$) .
Then based on those two conditions we can create a set $m_2$ such that there are candies identical to $m_1$ , or there are no candies identical to $m_1$.
To satisfy the question , i.e to tell the number of identical candies in $m_1$ and $m_2$, we must consider the second case for $m1$ and first case of $m_2$.
This is because we can see that for the other cases , we would end up with $0$ identical candies.
Note : you can switch choices for $m_1$ and $m_2$ as they are free choices.