Let $A = B = \mathbb{N}$ and let $$
f(n) = n+1 \text{.}
$$
Then $g(n) = n-1$ is obviously a left inverse since $(n + 1) - 1 = n$. Yet $f$ is not surjective - $f(\mathbb{N}) = \mathbb{N}\setminus\{0\}$.
You might object that, the way I defined it, $g$ isn't a function from $\mathbb{N} \to \mathbb{N}$, since $g(0)$ isn't defined. You're right of course, but that doesn't really matter, because $f(n) \neq 0$ for all $n \in \mathbb{N}$, so the value of $g(0)$ doesn't affect whether $g(f(n)) = n$ for all $n \in \mathbb{N}$. So you can just set $g(0) = 0$, and $g$ is still a left-inverse of $f$, and $f$ is still not surjective.
Also note that the corrected definition of $g$, i.e. $$
g(n) = \begin{cases} n-1 &\text{if $n \neq 0$} \\
0 &\text{otherwise} \end{cases}
$$
is not injective - you have $g(1) = g(0) = 0$. And since $f$ is $g$'s right-inverse, it follows that while a function must be injective (but not necessarily surjective) to have a left-inverse, it doesn't need to be injective (but does needs to be surective) to have a right-inverse.