Track Daily Secret Sharing before Each Person Forgets
Company: Bloomberg
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Other
### Problem
One person learns a secret on day 1. A person who learns it on day `d` tells one new person each day from `d + delay` through `d + forget - 1`. On day `d + forget`, they forget and can no longer share it. Return the number of people who still know the secret at the end of day `n`, modulo `10^9 + 7`.
```cpp
class Solution {
public:
int peopleAwareOfSecret(int n, int delay, int forget);
};
```
### Examples
**Example 1:**
```text
Input: n = 3, delay = 1, forget = 2
Output: 2
Explanation: The day-1 learner forgets on day 3. The learners from days 2 and 3 still know the secret.
```
**Example 2:**
```text
Input: n = 5, delay = 3, forget = 5
Output: 3
Explanation: The original learner shares on days 4 and 5. Nobody has forgotten by day 5, so three people know it.
```
### Constraints
- `2 <= n <= 1000`.
- `1 <= delay < forget <= n`.
### Clarifying Questions
- Can someone share on the day they learn? No; `delay >= 1`.
- Can someone share on the day they forget? No.
- Is the result everyone who ever learned it? No; count only people who still know at the end of day `n`.
```hint Check the boundary
Mark the first sharing day and forgetting day for a person who learns on day1.
```
Overview: Count people who still know a secret after daily sharing delays and forgetting, returning the population at the end of the given day.
Track Daily Secret Sharing before Each Person Forgets
Bloomberg
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0
Problem
One person learns a secret on day 1. A person who learns it on day d tells one new person each day from d + delay through d + forget - 1. On day d + forget, they forget and can no longer share it. Return the number of people who still know the secret at the end of day n, modulo 10^9 + 7.
class Solution {
public:
int peopleAwareOfSecret(int n, int delay, int forget);
};
Examples
Example 1:
Input: n = 3, delay = 1, forget = 2
Output: 2
Explanation: The day-1 learner forgets on day 3. The learners from days 2 and 3 still know the secret.
Example 2:
Input: n = 5, delay = 3, forget = 5
Output: 3
Explanation: The original learner shares on days 4 and 5. Nobody has forgotten by day 5, so three people know it.
Constraints
2 <= n <= 1000
.
1 <= delay < forget <= n
.
Clarifying Questions Guidance
Can someone share on the day they learn? No;
delay >= 1
.
Can someone share on the day they forget? No.
Is the result everyone who ever learned it? No; count only people who still know at the end of day
n
.