Can you solve the prisoner hat riddle?

TED-ED RIDDLES S2 • E1 Can you solve the prisoner hat riddle? - Alex Gendler