If $A$ and $B$ have $n$ and $m$ elements respectively with $A\cap B=\emptyset$. Prove that $A\cup B$ has $m+n$ elements. If $A$ and $B$ have $n$ and $m$ elements respectively with $A \cap B=\emptyset$. Prove that $A \cup B$ has $m+n$ elements.
The solution in the book starts by letting $f$ be a bijection from $\{$1,..m$\}$ onto $A$ and $g$ a bijection from $\{$1,..n$\}$ onto $B$
Then proving the function
$h:=$$f(i)$ if $i=1,...,m$
Or $g(i-m)$ if $i=m+1,...,m+n$ is a bijection from $\{$1,..,m,m+1,..,m+n$\}$ onto $A$$\cup$$B$
But I'm stuck with the surjection part

Since $A$ has $m$ elements and $B$ has $n$ elements, there are bijections $f:\{1,\ldots,m\}\to A$ and $g:\{1,\ldots,n\}\to B$.
Now define $h:\{1,\ldots,m+n\}\to A\cup B$ by
$$
h(i) = \begin{cases}
f(i) & \text{if}\ i\in\{1,\ldots,m\}, \\
g(m-i) & \text{if}\ i\in\{m+1,\ldots,m+n\}.
\end{cases}
$$
First you should convince yourself that $h$ is well-defined.
To see that it is an injection, suppose $h(i)=h(j)$. Then either $i,j\in\{1,\ldots,m\}$ or $i,j\in\{m+1,\ldots,m+n\}$ because $A$ and $B$ are disjoint and $h$ maps $\{1,\ldots,m\}$ into $A$ and $\{m+1,\ldots,m+n\}$ into $B$. If $i,j\in\{1,\ldots,n\}$, then we have $f(i)=h(i)=h(j)=f(j)$, so the injectivity of $f$ gives $i=j$. Similarly we get $i=j$ if $i,j\in\{m+1,\ldots,m+n\}$.
For surjectivity, fix $x\in A\cup B$. Then either $x\in A$ or $x\in B$. If $x\in A$, we can use the surjectivity of $f$ to obtain $i\in\{1,\ldots,m\}$ such that $f(i)=x$. In this case $h(i)=f(i)=x$. On the other hand, if $x\in B$, then we can use the surjectivity of $g$ to obtain $i\in\{1,\ldots,n\}$ such that $g(i)=x$. Then $f(m+i)=g(i)=x$.
