Probability of a Car Passing By

Question: The probability of a car passing a certain intersection in a 20 minute windows is 0.9. What is the probability of a car passing the intersection in a 5 minute window? (Assuming a constant probability throughout)

Answer: This is one of the basic probability question asked in a software interview. Let’s start by creating an equation. Let x be the probability of a car passing the intersection in a 5 minute window.

Probability of a car passing in a 20 minute window = 1 – (probability of no car passing in a 20 minute window)
Probability of a car passing in a 20 minute window = 1 – (1 – probability of a car passing in a 5 minute window)^4
0.9 = 1 – (1 – x)^4
(1 – x)^4 = 0.1
1 – x = 10^(-0.25)
x = 1 – 10^(-0.25) = 0.4377

That was simple eh. Ready for a challenge? Have a look at some of the other probability questions.

If you like this post, please Digg it or thumbs up on stumble upon. 🙂

If you're looking for some serious preparation for your interviews, I'd recommend this book written by a lead Google interviewer. It has 189 programming questions and solutions:

Book Cover
Button
12 Comments

12 Responses

  1. If the probability of a car passing the intersection in 20 minutes is x%, the probability that it occurs in the first five minutes is (X/4)%. For the second five minutes, it’s also (X/4)%, etc. So the total for the 20 minutes is (X/4) + (X/4) + (X/4) + (X/4) = x%.

  2. Change the probability to 1. Roadblock?

  3. Steffen says:

    @Eric Fredine

    The integral of exp(ct) is 1/c*exp(ct). Additionally if you say the probability density is exp(ct) why can you say 0.1 = exp(20c). The density function does not give you the actual probability. You would have to integrate over t first.

    Am I missing something?

  4. Venkat says:

    TKI, sorry that’s not right.

    The probability of the event happening in 5 min interval must be obviously < 0!!!

  5. Venkat says:

    Abhishek, the problem assumes a constant distribution and hence the probabilities are equal.

    Let p = probability that the events happens in 5 min interval.

    Let q = probability of event happening in 20 min interval.

    Then probability of the event not happening in the 20 min interval is = (1-q)

    = (1-p)*(1-p)*(1-p)*(1-p)
    = (1-p)^4

    so, p= 1 – (1-q)^(1/4)

  6. mathie says:

    This solution seems synthetic to me. This is dividing time up into 5 minute intervals and treating the problem as a series of bernoulli trials.

    Why is the solution not based on poisson distribution?

  7. Eric Fredine says:

    Fun stuff. Here’s another solution:

    Since the probability throughput is constant, the probability density function for not seeing a car is given by:

    ProbNoCar(t) = e^ct where c is a constant that determines the rate of decay. The actual probability is given by the integral of e^ct which is e^ct (nice property of e).

    So, now we just need to determine c.

    ProbNoCar(20) = 0.1 = e^c*20
    c*20 = ln(0.1) = -2.3026
    c = -0.1151

    and plug in 5:
    ProbNoCar(5) = e^-0.1151*5 = 0.5623

    and subtract it from 1:
    ProbCar(5) = 1 – ProbNoCar(5) = 0.4377

  8. TKI says:

    Hi I read your solution for the above problem. Initially I found the solution convincing but I got stuck in the same logic you used

    you used that probability (of a car not passing in 20 minutes window) is 4 times of the probability (of a car not passing in 5 minutes window )

    Using the same logic
    probability (of a car passing in 5 minutes window ) = 1 – probability (of a car not passing in 5 minutes window )

    probability (of a car passing in 5 minutes window ) = 1 – [ {probability (of a car not passing in 20 minutes window )/4}]

    x = 1 – (0.1/4) gives x = 0.975

    kindly clear my problem

  9. Abhishek says:

    I beg to differ, and fail to agree with your solution.
    The hinge of your solution is that:-
    Probability that no car passes in a 20 minute window= ( P(no car passing in a 5 min. window))^4

    This reasoning, I think, is wrong. Its the following that makes sense:
    P(no car passing in a 20 min window)=
    P(no car passing in the first 5 mins)*P(no car passing in the second 5 mins)*P(no car passing in the third 5 mins)*P(no car passing in the last 5 mins)

    And the probability of a car going in each of the 5-min frame isn’t equal.. because, each probability depends upon the previous one.

    I have a solution(a rather lengthy one), crafted from my approach. Tell me if you agree so far, so that I may post it.

  10. Doggie says:

    That is a valid point. I guess I should have phrased the question as “at least one car passing by”. 🙂

  11. Gijs says:

    Isn’t this only valid if ‘a car passing by’ is meant to mean ‘one or more cars passing by’ instead of ‘exactly one car passing by’?

  12. Car Charity says:

    Blog looks really good mate, keep it up! The information is delivered solidly! 🙂

Leave a Reply

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>