There were three men in a line (facing forward) so they can only see the man (or men) in front of them. There are also five hats, two black and three white. Each man is wearing one of the hats.
When the man at the back of the line was asked "Do you know your hat color?", he replied "No". When the man that was second in line was then asked "Do you know your hat color?" he replied "No". When the man at the front of the line was asked "Do you know your hat color?" he replied "Of course".
What color of hat was the man at the front of the line wearing?
The man in front must be wearing white.
For the man in the back of the line (seeing two other hats) to say he doesn't know his own color, he must be looking at either 2 white hats or a black/white combination. If the second man in line, therefore, sees a black hat in front of him, he'd know from the response behind him that his must be the white hat in a b/w combo; since the second man didn't know his own color, though, he must have seen a white hat, and the man in front used this to deduce his own hat color.