GlobalLogic interview question

Prisoners hat problem?