dp
of length n
to store the number of people who learn the secret on each day.dp[0]
to 1 since one person knows the secret on day 1.share
to keep track of the number of people who can share the secret on a given day.n
:
a. Add the number of people who learned the secret delay
days ago to share
.
b. Subtract the number of people who learned the secret forget
days ago from share
.
c. Set dp[i]
to the current value of share
.dp
from n - forget + 1
to n
to get the total number of people who still remember the secret at the end of day n
.10^9 + 7
.