The problem goes as follows
Let $f:X\to Y$ be a function. Show that $f$ is injective if, and only if, for all set $Z$ and for all function $g:Z\to X$ and $h:Z\to X$, $f\circ g = f\circ h \implies g = h$.
I've managed to do the first half of the problem, but I can't figure out the rest. Here's what I've done:
We will first show that $f$ is injective implies $f\circ g = f\circ h \implies g = h$. $f\circ g = f\circ h \implies f\circ g (z) = f\circ h (z)\quad \forall z \in Z \iff f(g(z)) = f(h(z))$, but since $f$ is injective we have $g(z) = h(z)\implies g = h$.
So I proved it in one direction, but I can't manage to prove it in the other direction