• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Puzzle : 100 doors in a row Visit and Toggle the door. What state the door will be after nth pass ?

December 23, 2014 by Dhaval Dave

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 its 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.question: what state are the doors in after the last pass? which are open which are closed?

Solution

For example,
After the first pass every door is open.
Second pass you only visit the even doors (2,4,6,8…) so now the even doors are closed and the odd ones are opened.
Third time through you will close door 3 (opened from the first pass), open door 6 (closed from the second pass), etc..
Hint : Door 12 will be visited in 1, 2, 3, 4, 6 & 12 pass (divisors..)

You can figure out that for any given door,
Say door #42, you will visit it for every divisor it has.
42 has 1 & 42, 2 & 21, 3 & 14, 6 & 7. 

Pass 1 open the door,
Pass 2 close it.
Pass 3 open,
Pass 6 close.
Pass 7 open ….  pass 14 close, pass 21 open, pass 42 close. for every pair of divisors the door will just end up back in its initial state. 

So you might think that every door will end up closed?
Well what about door #9. 9 has the divisors 1 & 9, 3 & 3. but 3 is repeated because 9 is a perfect square, so you will only visit door #9, on pass 1, 3, and 9… leaving it open at the end.

Only perfect square doors will be open at the end.

This Puzzle was asked in Housing.co.in

Similar Articles

Filed Under: Adobe Interview Questions, Flipkart Interview Questions, Interview Questions, Microsoft Interview Questions Tagged With: Mathematical, Puzzle

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

Get K Max and Delete K Max in stream of incoming integers

SAP Interview Questions

Python Dictionaries

ADOBE Aptitude C Language Test

Maximum sum contiguous subarray of an Array

K’th Largest Element in BST when modification to BST is not allowed

Trie Dictionary

Find and print longest consecutive number sequence in a given sequence in O(n)

Spanning Tree

SAP Off Campus Hiring_ March 2015 Computer Skills

Check a String is SUBSEQUENCE of another String Find Minimum length for that ( DNA Matching )

Leetcode: Merge Intervals

DFS (Depth First Search)

Convert Decimal to Roman numbers / Romanizer HackerEarth Code

Find an index i such that Arr [i] = i in array of n distinct integers sorted in ascending order.

Check Binary Tree is Binary Search Tree or not

25 horses 5 tracks Find 3 fastest puzzle

Max Sum in circularly situated Values

VMWare SDEII Interview

Binary Tree in Java

N teams are participating. each team plays twice with all other teams. Some of them will go to the semi final. Find Minimum and Maximum number of matches that a team has to win to qualify for finals ?

Maximum occurred Smallest integer in n ranges

building with N steps, we can take 1,2,3 steps calculate number of ways to reach at top of building

In Given LinkedList Divide LL in N Sub parts and delete first K nodes of each part

robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

Subset Sum Problem Dynamic programming

Top 10 Interviews Techniqes for Campus Interview in IIT NIT BITS for MTech

Circular Linked List

Find the smallest window in a string containing all characters of another string

The Magic HackerEarth Nirvana solutions Hiring Challenge

Copyright © 2025 · Genesis Framework · WordPress · Log in