Find number of onto functions if $f(x_1)=y_1$ and $f(x_2)=y_2$ Given $A=\left\{x_1,x_2,x_3,x_4,x_5\right\}$ and $B=\left\{y_1,y_2,y_3,y_4\right\}$ Find number of onto functions if $f(x_1)=y_1$ and $f(x_2)=y_2$ 
Now onto function means every element in codomain should have atleast one pre image.So $y_3$ has 3 ways to choose its pre image since $x_1$ and $x_2$ have fixed mappings. Once $y_3$ has chosen, then $y_4$ has two possibilities to choose its pre image. Now finally there is one element remaining in  domain which has $4$ ways to choose its image. so total ways is $3 \times 2 \times 4=24$
But my book answer is $18$, can i know my mistake
 A: You choose a preimage for $y_3$ in three ways, then a preimage for $y_4$ in two ways, and an image of the remaining element in four ways. I think you are overcounting.
For example, suppose that you choose a preimage of $y_3$ : $f(x_3) = y_3$, a preimage of $y_4$ : $f(x_4) = y_4$, and for the leftover $x_5$, you choose $f(x_5) = y_3$. This is an onto mapping.
However, you could also have gone like : choose a preimage of $y_3$ : $f(x_5) = y_3$, a preimage of $y_4$ : $f(x_4) = y_4$, and for the leftover $x_3$, you choose $f(x_3) = y_3$. This is an onto mapping, and it's exactly the same, however, you have counted it twice.
The answer is here: The point is, since the map is onto, each element has one preimage, but one of the elements has two preimages. By making a choice of this element, we can partition into cases.
Suppose $y_1$ has two preimages. Then, one of these is $x_1$, the other can be chosen in $3$ ways. The remaining two elements in $A$ will map to $y_3,y_4$ in some order, this is done in $2$ ways. So the answer is $6$.
The same applies for $y_2$, so here we get $6 \times 2 = 12$ ways.
Suppose $y_3$ has two preimages. Then, choose these two elements out of $x_3,x_4,x_5$, this is done in $3$ ways. The remaining one gets mapped to $y_4$. So there are three ways of doing it.
A similar argument applies for $y_4$, so here we get $3 \times 2 = 6$ ways.
Totaling up, $6+12= 18$ is the answer in your book.
I want to point out : All the above cases are disjoint and complete, and in your case, they were not. Disjointness comes from the fact that in each case, the element having two preimages was different, therefore no function appears in two cases, however every function must appear in at least one case.
