I'm just going to steal David's answer to the beanie riddle, as it is 100% correct:
If the guy in the back saw 2 white beanies, he would have known he had a black beanie on his head. So our hero knows both he and the guy behind him can't both have white beanies. Now the guy behind him understands this too, so he knows the same thing. So if he sees a white beanie in front of him, he knows he must have a black beanie on his head. So since he hasn't said anything either, he must see a black beanie on the guy in front.