Data Interview Question

Lost Miner and the Maze of Paths

bugfree Icon

Hello, I am bugfree Assistant. Feel free to ask me for any question related to this problem

Solution & Explanation

Problem Breakdown

In this problem, we need to calculate the expected number of days a miner will spend in a maze before reaching safety. The maze has two initial paths, A and B, with subsequent paths BA and BB stemming from B. The miner's choices are random and he forgets previous decisions.

  • Path A: Loops back to the start, taking 5 days.
  • Path B: Leads to a junction instantly (0 days).
    • Path BA: Returns to start, taking 2 days.
    • Path BB: Leads to safety, taking 1 day.

The miner has an equal probability of choosing any path.

Concepts Used

  • Geometric Distribution: Models the number of trials until the first success.
  • Linearity of Expectation: The expected value of a sum of random variables is the sum of their expected values.

Step-by-Step Solution

  1. Define Variables

    • Let E[D]E[D] be the expected number of days the miner spends in the maze.
    • Let E[W]E[W] be the expected number of walks (or rounds) the miner takes.
  2. Probability Calculations

    • Probability of choosing Path A: P(A)=0.5P(A) = 0.5
    • Probability of choosing Path B: P(B)=0.5P(B) = 0.5
    • Probability of choosing Path BA from B: P(BAB)=0.5P(BA | B) = 0.5
    • Probability of choosing Path BB from B: P(BBB)=0.5P(BB | B) = 0.5
    • Therefore, P(BB)=P(BBB)×P(B)=0.25P(BB) = P(BB | B) \times P(B) = 0.25
  3. Expected Walks (Trials)

    • Since the miner succeeds (reaches safety) with probability 0.25 each round, the number of rounds follows a geometric distribution: E[W]=1P(BB)=4E[W] = \frac{1}{P(BB)} = 4
  4. Expected Days per Walk

    • Calculate the expected number of days per walk: E[D/W]=P(A)×5+P(BA)×2+P(BB)×1=0.5×5+0.25×2+0.25×1=3.25E[D/W] = P(A) \times 5 + P(BA) \times 2 + P(BB) \times 1 = 0.5 \times 5 + 0.25 \times 2 + 0.25 \times 1 = 3.25
  5. Total Expected Days

    • The total expected number of days is the product of the expected number of walks and the expected days per walk: E[D]=E[W]×E[D/W]=4×3.25=13E[D] = E[W] \times E[D/W] = 4 \times 3.25 = 13

Conclusion

The expected number of days the miner will spend in the maze before reaching safety is 13 days. This solution leverages the geometric distribution to model the number of rounds and uses linearity of expectation to calculate the expected number of days per round.