Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Black and White Hats

Black and White Hatsfooter line

 

One hundred students stand in line, one in front of the other, each wearing a black hat or a white hat. Every student can see the hats of their classmate in front but not their hats or those worn by anyone behind. The class teacher starts at the back of the line and asks each student the colour of their hat. If they answer correctly, they will pass the final exam. If they get it wrong, they’ll fail. How many students will pass at most if they are allowed to discuss a strategy before their teacher starts asking the colours of their hats?

 

FOR SOLUTION SCROLL TO THE NEXT PAGE!!!!

 

Solution: 

Ninety-nine students can pass the final exam by using a simple strategy. The students decide that the last standing student will count and shout the colour in odd numbers in front. Going ahead, the other students can use simple maths to predict their hat colour. The 100th student also has a 50-50 chance.

Ex: The 100th student sees the number of white hats in front is odd, so he says white. The 99th kid now counts the number of white hats in front. If it is odd, then he has a white hat. Else he has the black hat, and similarly, other students can predict their cap colour.