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

Interview with Hinako Sato -Vice Chair of Events at Women In Music Boston

Why You should Take Company Culture into Account in Your Next Interview

Seven tragedies of paper for HVAC Businesses — Fieldinsight

Weeknotes s01e39

5 main points for teams to achieve high impact with less overload through OKRs

Non-transactional relationships

Why Athletes Should Become Entrepreneurs When They Retire

The Power of Delegation

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

Dinner Hand Shakes Puzzle

One interview, Many learnings

Preparing for your first code test