A friend has given me this task and asked for help. I immediately tried picking various $f$ and $g$ such that $g$ and $g\circ f$ are both surjective but $f$ is not. However, i always found myself restricting $\mathbb{R}$ to some subsets $A \subset \mathbb{R}$ in order to make it work. I can't figure out how to prove it for
$$ \mathbb{R} \xrightarrow{f} \mathbb{R} \xrightarrow{g} \mathbb{R}$$
Is it even possible? I also tried using sectionwise defined functions (different functions for $x \ge 0$ and $x < 0$). However, no success.
Any advise? I'm starting to assume that it's not possible for $\mathbb{R}$ without any restrictions.
Thanks for any help!


Take, for instance,$$f(x)=\begin{cases}x&\text{ if }x\leqslant-1\\x+3&\text{ otherwise}\end{cases}\text{ and }g(x)=x^3-3x.$$It is clear that $f$ is not surjective. However,$$g\bigl(f(\mathbb{R})\bigr)=g\bigl((-\infty,-1]\cup(2,+\infty)\bigr)=\mathbb R.$$