Interview Query

Rain in N Days

Start Timer

0:00:00

Upvote
14
Downvote
Save question
Mark as completed
View comments (16)
Next question

The probability that it will rain tomorrow is dependent on whether or not it is raining today and whether or not it rained yesterday.

If it rained yesterday and today, there is a 20% chance it will rain tomorrow. If it rained one of the days, there is a 60% chance it will rain tomorrow. If it rained neither today nor yesterday, there is a 20% chance it will rain tomorrow.

Given that it is raining today and that it rained yesterday, write a function rain_days to calculate the probability that it will rain on the nth day after today.

Example:

Input:

n=5

Output:

def rain_days(n) -> 0.39968
.
.
.
.
.


Comments

Loading comments