Finding the Expected value

You are in a room; seeing n doors in front of you in beginning. You can choose any door you like. The probability for choosing a door is equal for all doors.

If you choose the ath door, it can either take you back to the same position where you begun in ti minutes, or can take you out of the maze after ti minutes. If you come back to the same position, you can't remember anything. So, every time you come to the beginning position, you have no past experience.

Now you want to find the expected time to get out of the room.

In the case if the particular door will get you back to same position.You'll be given the minutes in negative.

Suppose if the input is of the form For each door, -6 -9 ....-value Here everything is negative,so we cannot come out of the door.We have the probability here as "infinity"

Suppose if we have:

3 doors with values 3 -6 -9 The expected value is 18 ? but i don't understand how the answer is 18.Can someone please explain in simple terms ?

Source : This is a programming contest question.


Let $E$ be the expected number of minutes to escape. Then anytime you are in the room about to choose a door among the three mentioned,

$$E = \begin{cases} 3 & \text{ probability} \frac13 \\ 6+E & \text{ probability} \frac13 \\ 9+E & \text{ probability} \frac13 \end{cases}$$

Thus we have $E = \frac13 \times 3 + \frac13 \times (6+E) + \frac13 \times (9+E) \implies 3E = 18 + 2E \implies E = 18$.

You can extend the logic to more doors / other times...