Hats and Genie Puzzle-Asked in interviews.


A bunch of men are on an island.
A genie comes down and gathers everyone together and places a magical hat on some people’s heads (i e , at least one person has a hat).

The hat is magical: it can be seen by other people, but not by the wearer of the hat himself. To remove the hat, those (and only those who have a hat) must dunk themselves underwater at exactly midnight. If there are n people and c hats, how long does it take the men to remove the hats?
The men cannot tell each other (in any way) that they have a hat.

A) N days

B) C days

C) N + C days

D) N * C days

Solution: B is the solution

Let's take some simple cases first c = 1: in this case person who has hat on his head can see that no one else has hat on their head, so he will understand that he is the one with hat.c = 2: in this case person with hat will see one other person with hat, rest all will see two hats. Now had there been only 1 hat, this case would have been solved on very first day, but in this case no one will go on first night, so the guy who see one hat will understand that there must be one hat on his head, so both of them will go underwater on second night.c = 3: in this case person with hat will see two hats and rest all will see three hats, now had there been 1 or 2 hats some guys would have gone on first or second night, thus on third day guys who see 2 hats will understand that they have hats on their head and they will all go underwater on third night.Similarly we can see that it will take c days to remove all hats.

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.




Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

5 assumptions about how to engage Gen Z in the workplace

Managing software teams in academia and industry

In Order to Grow, Service-Based Employees Must Let It Fail

Account Based Selling Team: Start the Year by Getting Personal

Process safety — 21st century and beyond

From Pain To Purpose….

“I’m a better leader because I know what it is like to sit in front of a Staples crying in my car…

How to Address Contention in the Workplace

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Upskilling students for tech placements!

More from Medium

Two Pills Each Day

Valid Palindrome II

Jelly Beans Jars Puzzle

Minimum Batteries