Answer :
If the person at the back saw two black hats, he would immediately know that he wore a white hat. He does not, so the two front hats are either black and white, or both white. The second person would know this fact! If they saw a black hat in front of them, then they would know that their hat is white. Since they do not, the hat at the front must be white. The guy at the front realises all this, and knows that his hat is white.