Easy solution approach explained


#1

Tallest dwarf : shouts “white” if no of whites in front of him are odd , shouts “black” if no of whites in front of him are even.

so now every dwarf notes this result (if the total no of whites except the last person are even or odd)

Now, n-1th dwarf counts the number of whites in front of him (let this be r)
if r is odd and the number of hats according to tallest are also odd…then he is wearing black.
if r is even and the number of hats according to tallest are also even…then he is wearing black
remaining cases its white…

Now, when this n-1th dwarf shouts out white => then all the other dwarves update their reading as odd from n-1th position if even from nth position(shouted by tallest) and vice versa…
and if he shouts out black then the readings are not updated…
…so similarly every dwarf calculates their hat color and only tallest one may die…so max is 1.


#2

@bvabhi249052 nice explanation…


#3

The last dwarf in line don’t know the colour of his hat but he can shout the colour of dwarf standing just after him so only that one die and other listen their colour from the dwarf standing just behind them.