Can a function have overlapping range? Consider the function $f : \mathbb{R}\rightarrow\mathbb{R}$ defined by
$$f(x)=\left\{\begin{align}x^2 - 2 & \text{if}\,x > 0,\\
x - 1 & \text{if}\, x \le 0.\end{align}\right.$$
Find a right inverse of $f$.
The answer that I came up to this question was this:
$$f(g(x)) = x$$
$$g(x) = \left\{\begin{align} \sqrt{x+2} & \text{if}\, x > -2,\\
x + 1 & \text{if}\, x\le -1.\end{align}\right.$$
However, the ranges $-1 \ge x > -2$ overlap. Since the definition of a function is that each $x$ maps to only 1 $y$, if $x = -1$ then there are potentially 2 $y$ that it could map to: $1$ and $0$. So is this therefore not a function? How can it not be the right answer?  

You are right in that your $g$ is not a function.
In the overlapping range, you need to decide which one of the two branches to choose.
Solution:
For example, you can choose
$$g(x)=\left\{\begin{align}\sqrt{x+2} & \text{if}\,x>-2\\
x+1 & \text{if}\,x\le -2\end{align}\right.$$
Now suppose that $x>-2$. Then $\sqrt{x+2}>0$ and therefore $f(g(x))=f(\sqrt{x+2})=(\sqrt{x+2})^2-2=x$.
Suppose that $x\le -2$. Then $x+1\le -1\le 0$. So $f(g(x))=f(x+1)=(x+1)-1=x$.
Altogether, $g$ is a right inverse of $f$.
In the range from $-2$ to $-1$ you are free to choose any of the two branches.
Every choice (even if it's different at every point, i.e. if you jump between branches all the time) will give you a right inverse.
