Solution: Number of People Aware of a Secret
Explore a dynamic programming method to calculate how many people know a secret at the end of n days. Understand how to use a dp array to track people discovering the secret daily, manage sharing delays, and handle forgetting, all while optimizing with modular arithmetic.
We'll cover the following...
Statement
On day
Each person who learns the secret will begin sharing it with one new person every day, but only after a waiting period of delay days from when they first discovered it. Additionally, each person completely forgets the secret forget days after discovering it. Once a person has forgotten the secret (on the day of forgetting and all subsequent days), they can no longer share it.
Given an integer n, determine how many people know the secret at the end of day n. Since the result can be very large, return it modulo
Note: A person who discovered the secret on day
dcan share it starting from dayd + delaythrough dayd + forget - 1(inclusive), and they forget it on dayd + forget.
Constraints:
...