100 Doors — Puzzle for Interview rounds

Placewit
2 min readJun 17, 2021

Question :

There are 100 doors in a row, all doors are initially closed. A person walks through all doors multiple times and toggle (if open then close, if close then open) them in following way:

In first walk, the person toggles every door

In second walk, the person toggles every second door, i.e., 2nd, 4th, 6th, 8th, …

In third walk, the person toggles every third door, i.e. 3rd, 6th, 9th, …

………
……….

In 100th walk, the person toggles 100th door.

Which doors are open in the end?

Solution :

A door is toggled in ith walk if i divides door number. For example the door number 45 is toggled in 1st, 3rd, 5th, 9th ,15th and 45th walk.
The door is switched back to an initial stage for every pair of divisors. For example, 45 is toggled 6 times for 3 pairs (5, 9), (15, 3) and (1, 45).
It looks like all doors would become closes at the end. But there are door numbers which would become open, for example, 16, the pair (4, 4) means only one walk. Similarly all other perfect squares like 4, 9, ….

So the answer is 1, 4, 9, 16, 25, 36, 49, 64, 81 and 100.

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.

--

--