WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Wall Street Quant · Puzzles & Problems · question 32 of 155

You have 100 doors in a row that are all initially closed. You make 100 passes by the doors starting with the first door every time. The first time through you visit every door and toggle the door (if the door is closed, you open it; if it is open, you close it). The second time you only visit every 2nd door (door #2, #4, #6, ...). The third time, every 3rd door (door #3, #6, #9, ...), etc, until you only visit the 100th door. After your last pass, which doors are open and why?

📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

To solve this problem, we first need to figure out how many times each door is toggled. Each door’s number represents the factors of that number. For example, door #6 will be toggled on the 1st, 2nd, 3rd, and 6th passes since these are the factors of 6. So, the number of times a door is toggled is equal to the number of factors it has.

Now, let’s analyze the pattern here. If a door has an **even** number of factors, it will end up being closed. This is because an even number of toggles will bring the door back to its initial state (closed). Conversely, if a door has an **odd** number of factors, it will end up being open.

So, the problem boils down to finding all the doors with an odd number of factors. Notice that factors usually come in pairs, by definition. For example, the factors of 6 are (1, 6) and (2, 3). So, most numbers have an even number of factors, and it’s only when the two factors making up a pair are the same that we get an odd number of factors. This occurs for perfect squares, like 4 (1x4, 2x2), 9 (1x9, 3x3), etc.

Given this observation, we can conclude that the doors which will be open at the end are those that are perfect squares. Let’s find all the perfect squares from 1 to 100:

1, 4, 9, 16, 25, 36, 49, 64, 81, 100

So, doors #1, #4, #9, #16, #25, #36, #49, #64, #81, and #100 will be open after 100 passes.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Wall Street Quant interview — then scores it.
📞 Practice Wall Street Quant — free 15 min
📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

All 155 Wall Street Quant questions · All topics