Show that the determinant of
$$M=\begin{pmatrix}0&1&1&1&\cdots&1\\1&0&1&1&\cdots&1\\1&1&0&1&\cdots&1\\1&1&1&0&\cdots&1\\\vdots&\vdots&\vdots&\vdots&&\vdots\\1&1&1&1&\cdots&0\end{pmatrix}$$
is nonzero.
Solution I was provided: If the above matrix is $n\times n$ then
$$\begin{pmatrix}0&1&1&\cdots&1\\1&0&1&\cdots&1\\1&1&0&\cdots&1\\\vdots&\vdots&\vdots&&\vdots\\1&1&1&\cdots&0\end{pmatrix}\begin{pmatrix}n-2&-1&-1&\cdots&-1\\-1&n-2&-1&\cdots&-1\\-1&-1&n-2&\cdots&-1\\\vdots&\vdots&\vdots&&\vdots\\-1&-1&-1&\cdots&n-2\end{pmatrix}=\begin{pmatrix}-(n-1)&0&0&\cdots&0\\0&-(n-1)&0&\cdots&0\\0&0&-(n-1)&\cdots&0\\\vdots&\vdots&\vdots&&\vdots\\0&0&0&\cdots&-(n-1)\end{pmatrix}$$
Clearly the determinant of the right hand matrix is just the product of the diagonal entries, which is nonzero $(n$ is assumed to be at least 3). Since for any square matrices $A$ and $B,\det(AB)=$ $\det(A)\det(B)$, we must have that the determinant of both matrices on the left hand side are nonzero as well.
Can someone explain how does the solution work, I don't get why we multiply M by this specific matrix? And why does it only work for n greater than 3, not 2?