Answer:
At-most 99 prisoners can be saved and the 100th prisoner has 50-50 chances of being executed.
The idea is that every prisoner counts number of red hats in front of him.
100th prisoner says red if the number of red hats is even. He may or may not be saved, but he coneys enough information to save 99th prisoner.
The 99’th prisoner decides his answer on the basis of answer of 100’th prisoner’s answer. There are following possibilities and 99’th prisoner can figure out color of his hat in every case.
If 100’th prisoner said ‘Red’ (There must have been even number of red hats in front of him)
a) If 99’th prisoner sees even number of red hats in front of him, then his color is black.
b) If 99’th prisoner sees odd number of red hats in front of him, then his color is red.
If 100’th prisoner said ‘Black’ (There must have been odd number of red hats in front of him)
a) If 99’th prisoner sees even number of red hats in front of him, then his color is Red.
b) If 99’th prisoner sees odd number of red hats in front of him, then his color is Black.
The 98’th prisoner decides his answer on the basis of answer of 99’th prisoner’s answer and uses same logic.
Similarly other prisoners from 97 to 1 are saved