3 balls are distributed to 3 boxes at random. Number of way in which we set at most 1 box empty is: 3 balls are distributed to 3 boxes at random. Number of way in which we set at most 1
box empty is:
My approach:-
let no of box = $n$ & no of balls = $k$
and both are distinct.
Now required way ,
zero box empty + 1 box empty
$\implies n_{\mathrm{P }_{k}} + S(k,n) * n!$
$\implies 3_{\mathrm{P }_{3}} + S(3,2)*2$
$\implies 3! + 6 = 12$
where,
$\mathbf{S}(\mathbf{k},
 \mathbf{n}):-$ Stirling number of the second kind can be defined as $\mathrm{S}(\mathrm{k}, \mathrm{n})=\frac{1}{n !} \sum_{i=0}^{n-1}(-1)^{i} n_{C_{i}}(n-i)^{k}$
$=\frac{1}{n !}\left[n_{C_{0}}(n-0)^{k}-n_{C_{1}}(n-1)^{k}+n_{C_{2}}(n-2)^{k}+\cdots+(-1)^{n-1} n_{C_{n-1}}(1)^{k}\right]$
Edit $1$
I think first I have to choose the empty box doing $\binom{3}{1}$,then it becomes 3 balls into 2 boxes. So accordingly I can use the above mentioned process.(i.e $S(2,3)*3*2!$. that will lead me to $24$ .)But here one doubt arises in my mind! I am considering the case one box may contain atleast 1 ball it can go max to 3 balls also.But If I take 3 balls in a box another box will also remain empty ,so it becomes two boxes empty which is invalid.
But answer given is $24$.
In which step AM I wrong?
 A: Assuming the balls and boxes are distinguishable, you should have multiplied ${3 \brace 2}$ by $3!$ rather than $2!$ in the case where one box is left empty, where ${n \brace k} = S(n, k)$.
Let's look at the case where exactly one box is left empty.  Two balls must be placed in one box, and the other ball must be placed in another. There are $\binom{3}{2}$ ways to choose which two balls are placed together in one box.  If the boxes are indistinguishable, we place these two balls in one box, and place the other ball in another box.  Thus, if the boxes were indistinguishable, the number of ways we can distribute three distinct balls to three indistinguishable boxes so that one box is left empty is
$${3 \brace 2} = \binom{3}{2} = 3$$
If the boxes are actually distinguishable, it matters which box receives two balls, which box receives one ball, and which box receives no balls.  There are $3!$ such assignments.  Thus, the number of ways to distribute three distinct balls to three distinct boxes so that exactly one box is left empty is
$${3 \brace 2}3! = 18$$
Since there are $3!$ ways to distribute three distinct balls to three distinct boxes so that no box is left empty, the number of ways to distribute three distinct balls to three distinct boxes so that at most one box is left empty is
$$3! + {3 \brace 2}3! = 24$$
An alternate approach
Assume the boxes are distinguishable from the outset.
No box is left empty:  There are $3! = 6$ ways to assign each of the three distinct balls to a different box.
Exactly one box is left empty:  If exactly one box is empty, there are three ways to decide which box will receive two balls and two ways to assign a second box to receive the remaining ball.  There are $\binom{3}{2}$ ways to decide which two balls are placed in the box which will receive two balls and one way to place the remaining ball in the box which will receive one ball.  Hence, there are
$$3 \cdot 2 \cdot \binom{3}{2} = 3!\binom{3}{2} = 18$$
ways to distribute three distinct balls to three distinct boxes so that exactly one box is left empty.
Thus, there are indeed
$$3! + 3!\binom{3}{2} = 6 + 18 = 24$$
ways to distribute three distinct balls to three distinct boxes so that at most one box is left empty.
A: I think the problem is that you should have $S(2,3)$ not $S(3,3)$ - if one is empty then you are partitioning $n=3$ balls into $k=2$ nonempty (unordered) sets. The factor of $3!$ is correct, because any such partition can be ordered into the three boxes in $3!$ ways.
[edit] The question was changed since this answer was written, and originally had ${}^3P_3+S(3,3)*3!=12$.
