# There are 100 doors and they are all closed. A person walks through these 100 doors 100 times. Each time he toggles some of the doors, i.e closes if open and opens if it is closed. In the first walk, he will toggle all the doors. In the second walk, he will toggle every second door, i.e., 2nd, 4th, 6th, 8th and so on. In the third walk, he will toggle every third door, i.e. 3rd, 6th, 9th and so on. So after the 100th walk, which doors will be open and which will be closed?

**Updated:**Nov. 27, 2020 —

**Training Time:**3 minutes

Overseen by: Archangel Macsika

**Topic:** Data Science.

**Difficulty:** Easy.

**Companies who previously asked this:** -

**Objective:** There are 100 doors and they are all closed. A person walks through these 100 doors 100 times. Each time he toggles some of the doors, i.e closes if open and opens if it is closed. In the first walk, he will toggle all the doors. In the second walk, he will toggle every second door, i.e., 2nd, 4th, 6th, 8th and so on. In the third walk, he will toggle every third door, i.e. 3rd, 6th, 9th and so on. So after the 100th walk, which doors will be open and which will be closed?

**Short Answer: doors number 1, 4, 9, 16, 25, 36, 49, 64, 81 and 100 will be open and rest will be closed**.

### Full Solution

Let's lay out the data we have:

There are 100 doors and they are all closed.

The person will perform 100 walks.

On the first walk, the person visits and opens all of the doors since they are all initially closed.

On the second walk, the person visits doors 2, 4, 6, ... 100, and closes them, since they are open from the previous visit.

On the third walk, the person visits doors 3, 6, 9, ... 99, and will either open or close them. Even numbers divisible by 3 such as 6, 12, 18, ... etc will be opened since they are closed, while the rest of the odd numbers will be closed.

On the fourth walk, the person visits doors 4, 8, 12, ... 100, and will either open or close them depending on the state. Even numbers divisible by 3 and 4 such as 12, 24, ... etc will be closed since they are open, while other even numbers divisible by 4 but not 3 such as 4, 8, 16 etc will be opened since they are close. Doors with odd numbers will odd number remain open.

Follow the same pattern and keeping track and bearing in mind that only perfect square numbers can have an odd number of factors, you will get the answers we got.

Take note, each time you pass a door number, the state of the door number will not change anymore. For instance, since we have done 1 to 4, door number 1 to 4 will not be affected anymore. And so far, 1 and 4 are opened.

At the end, doors number 1, 4, 9, 16, 25, 36, 49, 64, 81 and 100 will be open and rest will be closed.