One hundred persons will be lined up single file. Each person will be assigned either a red hat or a blue hat. No one can see the color of his or her own hat. However, each person is able to see the color of the hat worn by every person in front of him or her.
Beginning with the last person in line, each will be asked to name the color of his or her own hat. If the color is correctly named, the person lives; if incorrectly named, the person is shot dead on the spot. Everyone in line is able to hear every response as well as hear the gunshot;
Before being lined up, the 100 persons are allowed to discuss strategy, with an eye toward developing a plan that will allow as many of them as possible to name the correct color of his or her own hat (and thus survive). Once lined up, each person is allowed only to say “Red” or “Blue” when his or her turn arrives, beginning with the last person in line.
Develop a plan that allows as many people as possible to live.
On discussion among themselves , They agree that if the number of red hats that a person can see is even, that person will say red. If they add up to an odd number, he will say blue.
This way number 99 can look ahead and count the red hats. if they add up to an even number and number 100 said red, then 99 must be wearing a blue hat. if they add up to an even number and number 100 said blue, signalling an odd number of red hats, number 99 must also be wearing a red hat.
Number 98 knows that 99 said the correct hat, and so uses that information along with the 97 hats in front to figure out what color hat is on 98 head. And similarly , each of them can predict the color of his hat.
So,at max only one guy who is at back and calling for first time may get killed as his answer depends on number of red hats infront of him.
Though depending on his reply rest all of them will survive.