Four Criminals and Black and White Hats Riddle

Four criminals are caught and are to be punished. The judge allowed them to be freed if they solve a puzzle. If they do not, they will be hung. They agreed. The 4 criminals are lined up on some steps (as shown in the picture). They are all facing in the same direction. A wall