Let $p(n)$: If first $(n-1)$ people say no, the person in the first will say yes.
For $n = 1$ , there are no black hats$(n-1=1-1=0)$. Hence the first person will say “Yes colour of my hat is white.”
Suppose the statement is true for $n=k$.
See how the man standing in the front would think. Suppose my hatis black, then there are $k$ people with at least $k$ white hats and $k-1$ black hats.
By $p(k)$, since first $(k-1)$ person said no, the person behind me must say yes. "I know the colour of my hat is white"
If he says mo. So colour of my hat can not be black. Hence it is white.
So $p(k)$ is true
so, $p(k)$ is true $\implies$ $p(k-1)$ is true.
Hence by the principle of mathematical induction it is proved!
IF $n=2$, there is 1 black hat and at least 2 white hats. If the last person sees a black cap is put on by the person in front on him, he would definitely say "yes colour of my hat is white" as there is only 1 black hat.
But if he not able to answer first person will logically thinks he has put white hat and person behind him might have out black or white hat.