Solution (source code)

= Solution

This can fail. Let $X=\{1\}$ and $Y=\{a,b\}$, put $f(1)=a$, and let $g(a)=g(b)=1$. Then the <function composition> $g\circ f$ is the <identity function> on $X$, hence is a <surjective function>, although $f$ is not surjective.