Number of People Aware of a Secret

On day 1, one person discovers a secret.

You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are also given an integer forget, which means that each person will forget the secret forget days after discovering it.

A person cannot share the secret on the same day they forgot it, or on any day afterwards.

Given an integer n, return the number of people who know the secret at the end of day n. Since the answer may be very large, return it modulo 10^9 + 7.

Example 1
Inputn = 6, delay = 2, forget = 4
Output5
By day 6, B shares the secret with E and C shares it with F, so 5 people know the secret.
Example 2
Inputn = 4, delay = 1, forget = 3
Output6
By day 4, A forgets the secret while B, C, and D share it with three new people, leaving 6 people who know it.

Constraints

  • 2 <= n <= 1000
  • 1 <= delay < forget <= n

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate