Shouldn't this function be not invertible? Given question:

Define a function f : $\ D \to \mathbb{Z}$ by $\ f(x) = x^2 + 5 $, where $\ D = \{-4, -3, -2, -1, 0\} $.
Find $\ f^{-1} $.

My answer is that there isn't an inverse of function f because f is not bijective, as per I was taught and stated in my lecture notes. While f is one-to-one (injective), f is not onto (surjective) since set D only has 5 elements and the co-domain is the set of integers - not every element in the co-domain has a preimage.
However, the model answer given is such:

$\ y = x^2 + 5 \to x^2 = y - 5 \to x = \sqrt{y - 5} $
$\ f^{-1}(x) = -\sqrt{x-5} $

I have tried searching on this and everywhere seems to say the same thing E.g. link1, link2, link3 - that for a function to be invertible, it must be bijective.
I am rather confused at the moment... am I wrong and the model answer is correct?
Thanks!
 A: You are technically right. The function f is not invertible because it is not surjective.
However, f is invertible when limiting the co-domain to the range f(D) of the function. In that case, the function is the inverse.

$\ f^{-1}(x) = -\sqrt{x-5} $


Perhaps a even nicer way of writing that would be:

$\ g : \{ x \in \mathbb{Z} , x \geq 5\} \to D$
$\ g(x) = -\sqrt{x-5}$

Hence:

$f(D) = \{5, 6, 9, 14, 21, 30\}$
$\ g|_{f(D)} = f^{-1}$


Perhaps the biggest question is how you should answer this question in the first place.
Sure, being technically correct is important for math, but perhaps seeing "the big picture" that there is a condition for a inverse function when limiting its domain to specific subset is just as important. Figuring out the overall intent of the questions can be a very useful skill when trying to prove a statement.
If this is a "homework/exam question" though, keep in mind that this "see the big picture" and "common sense" is subjective - from my experience, different fields and mathematicians have different expectations and it is often worth to talk with your instructor to see how things align.
For instance, if I was working with someone that pointed that the function was not invertible because of the domain I would say something like "Sure, you are right, but you understood what I meant." in the sense of "Hey, this is probably just a detail in the whole scheme of what we are doing".
A: Note that the range of $f$ is $f(D) = \{5, 6, 9, 14, 21, 30\}$
\begin{align}
   \ y &= x^2 + 5 \\
   x^2 &= y-5 &\text{Note that $y-5 \ge 0$.} \\
   x &= -\sqrt{y-5}
\end{align}
