You are trapped in a room. There are n consecutive doors in front of you, with each door being behind the previous door. You need to open all doors to escape. In the same room, there are n switches and each switch connects to a different door. However, you don't know which switch connects to which door AND for some doors the "up" position will close the door while for other doors the "down" position will open the door. You will need to place all n switches in the correct configuration to escape. You can set the switches in any configuration and walk over to check which is the first closed door (since the doors are consecutive, you can't see the status of the doors behind the first closed one). What is an algorithm that will find the correct configuration to open all doors within O(n log n) trials?
You are trapped in a room. There are n consecutive doors in front of you, with each door being behind the previous door. You need to open all doors to escape. In the same room, there are n switches and each switch connects to a different door. However, you don't know which switch connects to which door AND for some doors the "up" position will close the door while for other doors the "down" position will open the door. You will need to place all n switches in the correct configuration to escape. You can set the switches in any configuration and walk over to check which is the first closed door (since the doors are consecutive, you can't see the status of the doors behind the first closed one).
What is an
Step by step
Solved in 3 steps