You have n balls numbered 1,2,…,n that you are placing in n distinct buckets. In how many ways can you do this such that:(i) no bucket remains empty? (ii) exactly one bucket remains empty?
$$\texttt{my attempt for part ii:}$$
Suppose we have n-1 buckets and n-1 balls, there are (n-1)! of placing these balls into these buckets. Then we have a single ball to place in n-1 buckets, therefore there is (n-1)(n-1)! However, there was a selection of one bucket out of n, which was left empty, and there is an overcount by 2. So, my final answer is: $\frac{(n-1)n!}{2}$
The correct answer is:$\binom{n}{2}n!$
Where did I go wrong?
So you first pick $1$ bucket that will go empty, then you pick one ball that will be distributed at the end. So $n^2$ possibilities. Then you place all balls in separate buckets, $(n-1)!$ possibilities. Then, among these $n-1$ buckets, you choose one that will receive the final ball, $n-1$ possibilities. So you overcount by $2$, because if the final configuration is such that balls $A$ and $B$ are in the same bucket (in that order), then it is the same as having $B$ and $A$ (i.e. whether we set $A$ or $B$ aside in the first iteration does not matter, the end result is the same). Maybe, this approach is easier:
First, pick $2$ buckets that will receive either $0$ or $2$ balls. Set them aside and for each remaining bucket (there are $n-2$ left, choose a ball numbered $1$ to $n$. There are $n \cdot (n-1) \cdots 3$ possibilities. For the remaining two balls, you have two possibilities, either place them in the first bucket or the second bucket we set aside.