A total of $r$ keys are to be put, one at a time, in $k$ boxes, with each key independently put in box $i$ with probability $p_i$ (hence, $\sum_{i=1}^k p_i = 1$). Each time a key is put in a non-empty box, we say that a collision occurs. Find the expected number of collisions.
Let random variable $X$ be the number of collisions. I first tried to derive the PMF of $X$, but got stuck. How would I do this?
In this answer I will not find the PMF of $X$ but the expectation of $\mathsf EX_i$ where $X_i$ denotes the number of collisions that take place in box $i$ (see my comment on the question).
If $Y_i$ denotes the number of keys that are put in box $i$ then we can find $Y_i$ again by linearity of expectation. But unfortunately we do not have $X_i=Y_i-1$ (which is about the first thing that comes to mind). This because $X_i$ takes value $0$ if $Y_i=0$.
That fact forces us to find the PMF of $X_i$.
Then it remains to find $\mathsf EX_i=\sum_{n=0}^{r-1}n\mathsf P(X_i=n)$.
And after that $\mathsf EX=\sum_{i=1}^k\mathsf EX_i$.
edit:
Note that $X_i=Y_i-1+\mathbf1_{Y_i=0}$ and $Y_i\sim\mathsf{Bin}(r,p_i)$ so that:$$\mathsf EX_i=\mathsf EY_i-1+\mathsf P(Y_i=0)=rp_i-1+(1-p_i)^r$$
So we end up with:$$\mathsf EX=\sum_{i=1}^k[rp_i-1+(1-p_i)^r]=r-k+\sum_{i=1}^k(1-p_i)^r$$