The Number of People Aware of a Secret problem simulates secret spreading: on day 1, one person learns a secret. Starting on day delay, they begin sharing it. After forget days from learning, they forget it. Each day, everyone who knows the secret (and hasn't forgotten) shares it with one new person. Count the total people who know the secret on day n. This coding problem uses a queue/DP simulation.
NCR, Arcesium, Microsoft, Amazon, and Bloomberg ask this to test queue-based simulation combined with DP. It validates understanding of "sliding window" growth — only active knowers in the window [delay, forget) share the secret. The queue, simulation, and dynamic programming interview pattern is directly applied.
DP with running window sum. dp[i] = number of people who first learn the secret on day i. For each day i from 2 to n: dp[i] = sum of dp[j] for all j where i - forget < j <= i - delay (people who learned within the active sharing window). Use a prefix sum or sliding window to compute this efficiently. Answer = sum of dp[j] for j in (n-forget, n].
n=6, delay=2, forget=4. dp[1]=1.
Secret/virus spreading problems are "sliding window DP" problems. The number of new learners on day i = sum of dp[j] for j in a window relative to i. Use prefix sums to make this O(1) per day. Practice epidemic simulation DP problems — SIR models, infection spread, rumor propagation — they all follow the same sliding window sum pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Time Needed to Rearrange a Binary String | Medium | Solve | |
| Time Needed to Buy Tickets | Easy | Solve | |
| Time Taken to Cross the Door | Hard | Solve | |
| Reveal Cards In Increasing Order | Medium | Solve | |
| Number of Students Unable to Eat Lunch | Easy | Solve |