Xét \(f\left(x\right)=x^2+2x+a-4\Rightarrow f'\left(x\right)=2x+2=0\Rightarrow x=-1\)
\(y\left(-2\right)=\left|a-4\right|\) ; \(y\left(1\right)=\left|a-1\right|\) ; \(y\left(-1\right)=\left|a-5\right|\)
\(\Rightarrow y_{max}=max\left\{\left|a-1\right|;\left|a-5\right|\right\}\)
Mặt khác:
\(max\left\{\left|a-1\right|;\left|a-5\right|\right\}=max\left\{\left|a-1\right|;\left|5-a\right|\right\}\ge\frac{\left|a-1\right|+\left|5-a\right|}{2}\ge\frac{\left|a-1+5-a\right|}{2}=2\)
\(\Rightarrow y_{max}\) nhỏ nhất bằng 2 khi \(\left\{{}\begin{matrix}\left(a-1\right)\left(5-a\right)\ge0\\a-1=5-a\end{matrix}\right.\) \(\Rightarrow a=3\)