Solution (source code)

= Solution
{c}

The <product rule> gives $y'=x^nz'+nx^{n-1}z$ and $y''=x^nz''+2nx^{n-1}z'+n(n-1)x^{n-2}z$. On an <interval> avoiding $x=0$, substitution and division by $x^{n+2}$ give
$$
z''+\left(2+\frac{2n+4}{x}\right)z'
+\left(2+\frac{2n+4}{x}+\frac{n^2+3n+2}{x^2}\right)z=0.
$$
For a <constant-coefficient differential equation>, the coefficient of $z'$ forces $2n+4=0$. At $n=-2$, the remaining coefficient $n^2+3n+2$ also vanishes. Thus
$$
\boxed{n=-2,\qquad z''+2z'+2z=0.}
$$
The <characteristic equation of a constant-coefficient differential equation> is $r^2+2r+2=0$, with <complex conjugate> <roots of a polynomial> $-1\pm i$. Its real solutions $e^{-x}\cos x$ and $e^{-x}\sin x$ are <linearly independent>. Therefore the <general solution> is
$$
\boxed{y(x)=\frac{e^{-x}}{x^2}(A\cos x+B\sin x),\qquad x\ne0.}
$$
The constants can be chosen independently on the two sides of the singular point. The <power substitution reducing a differential equation to constant coefficients> here is invertible wherever $x\ne0$.