What is the value of $a^2+b^2$? 
If the range of the function $$f(x)=\frac{x^2+ax+b}{x^2+2x+3}$$ is
  $[-5,4]$ then what is the value of $a^2+b^2$ ?
[$a,b$ are natural numbers]

What will the correct approach to this problem?
I tried using the general method as follows:
$({x^2+2x+3})y={x^2+ax+b}$
or,$x^2(y-1)+x(2y-a)+(b-3y)=0$
Then since $x$ is real the discriminant should be greater than equal to 0.
But this method isn't very efficient and quick for this problem.Any shortcuts possible?
 A: 
Note that
  $$-5 \leq y \leq 4 \iff (y+5)(y-4) \leq 0 \iff y^2+y-20 \leq 0$$

For $x^2(y-1)+(2y-a)x+(3y-b)=0$ admits real value of $x$,
\begin{align*}
  \Delta & \geq 0 \\
  (2y-a)^2-4(y-1)(3y-b) & \geq 0 \\
  -8y^2+4(3-a+b)y+a^2-4b & \geq 0 \\
  8y^2+4(a-b-3)y-a^2+4b & \leq 0 \\
\end{align*}
Comparing coefficients,
$$8y^2+4(a-b-3)y-a^2+4b \equiv 8(y^2+y-20)$$
$$\implies
\left \{
  \begin{align*}
    a-b-3 &= 2 \\ -a^2+4b &= -160
  \end{align*}
\right.$$
$$\implies (a,b)= (14,9) \: \text{ or } \: (-10,-15)$$
Since $a$ and $b$ are natural numbers, reject $\, (a,b)=(-10,-15)$.
$$\therefore \quad a^2+b^2=277$$
A: Both the quadratic equations
$$
f(x)=-5
$$
and
$$
f(x)=4
$$
must have double roots. If these equations have no roots, then the corresponding value is not in the range. But if either has two roots, then in between them the function will go outside the prescribed range.
So the discriminants $\Delta_1$ of both $(x^2+ax+b)+5(x^2+2x+3)$ and
$\Delta_2$ of $(x^2+ax+b)-4(x^2+2x+3)$ must both vanish. In other words
$$
\begin{aligned}
0&=\Delta_1=a^2+20a-260-24b,\\
0&=\Delta_2=a^2-16a-80+12b.
\end{aligned}
$$
This system is easy to solve. There are two solutions $(a,b)=(-10,-15)$ and
$(a,b)=(14,9)$.
