If $y=kx-2$ is tangent to the curve $y=3x^2+x+1\;,$ Then These two equation has exactly one
Solution. So Put $y=kx-2$ in $y=3x^2+x+1\;,$ We get $3x^2+x+1 = kx-2$
We get $3x^2+(1-k)x+3=0\;,$ Now for exactly one solution $\bf{Discriminant =0}$
So $$(1-k)^2-4\cdot 3 \cdot 3 = 0\Rightarrow (k-1)^2-(6)^2=0$$
So we get $$(k-1-6)\cdot (k-1+6) = 0\Rightarrow k=7\;\;,k=-5$$
$$\bf{Using \; calculus::}$$
If $f(x)=kx-2$ and $g(x)=3x^2+x+1$ are tangent to each other, Then Slope of tangent
at there common points $P(x_{1},y_{1})$ are equal.
So $$\displaystyle \left[f'(x)\right]_{(x_{1},y_{1})} = k$$ and $$\displaystyle \left[g'(x)\right]_{(x_{1},y_{1})} = 6x_{1}+1$$
So $$\displaystyle \left[f'(x)\right]_{(x_{1},y_{1})} = \left[g'(x)\right]_{(x_{1},y_{1})}\Rightarrow k=6x_{1}+1$$
Now Points $P(x_{1},y_{1})$ also lie on $f(x)$ and $g(x)$ (bcz it is a common point)
So $$kx_{1}-2 = 3x^2_{1}+x_{1}+1\Rightarrow (6x_{1}+1)x_{1}-2 = 3x^2_{1}+x_{1}+1$$
so we get $$3x^2_{1} = 3\Rightarrow x_{1} = \pm 1$$
Now Put into $k=6x_{1}+1\;,$ We get $k=7$ and $k=-5$