Let $M$ be a real $n\times n$ matrix with all diagonal entries equal to $r$ and all non-diagonal entries equal to $s$. Compute the determinant of $M$. This was a question from ISI M.Math test $2021$.
My attempt: I tried directly computing for small $n$ to see if there are any patterns. For $n=1,2,3$ the determinants are respectively $r, r^2-s^2, r^3+2s^3-3rs^2$. I couldn't find any pattern other than the obvious fact that there has to an entry $r^n$ for each $n$ so that the identity matrix satisfies the formula. And the sum of the coefficients must be zero for $n>1$ (by having a matrix with all entries equal to $1$). But I can't proceed any further.
I would rewrite $M=(r-s)I+A$ where $A$ is a matrix whose entries are identically $s$.
Now, it is easy to check that eigenvalues of $A$ are
with algebraic multiplicities $n-1$ and $1$ respectively.
The eigenvalues of $(r-s)I+A$ will be $(r-s)+0$ and $(r-s)+ns$ with same multiplicities.
Determinant being product of eigenvalues, we have $$\det(M)=(r-s)^{n-1}(r-s+ns)$$
The question in this post is a special case.