2327. Number of People Aware of a Secret Medium
1/**
2 * [2327] Number of People Aware of a Secret
3 *
4 * On day 1, one person discovers a secret.
5 * 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.
6 * 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.
7 *
8 * Example 1:
9 *
10 * Input: n = 6, delay = 2, forget = 4
11 * Output: 5
12 * Explanation:
13 * Day 1: Suppose the first person is named A. (1 person)
14 * Day 2: A is the only person who knows the secret. (1 person)
15 * Day 3: A shares the secret with a new person, B. (2 people)
16 * Day 4: A shares the secret with a new person, C. (3 people)
17 * Day 5: A forgets the secret, and B shares the secret with a new person, D. (3 people)
18 * Day 6: B shares the secret with E, and C shares the secret with F. (5 people)
19 *
20 * Example 2:
21 *
22 * Input: n = 4, delay = 1, forget = 3
23 * Output: 6
24 * Explanation:
25 * Day 1: The first person is named A. (1 person)
26 * Day 2: A shares the secret with B. (2 people)
27 * Day 3: A and B share the secret with 2 new people, C and D. (4 people)
28 * Day 4: A forgets the secret. B, C, and D share the secret with 3 new people. (6 people)
29 *
30 *
31 * Constraints:
32 *
33 * 2 <= n <= 1000
34 * 1 <= delay < forget <= n
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/number-of-people-aware-of-a-secret/
40// discuss: https://leetcode.com/problems/number-of-people-aware-of-a-secret/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn people_aware_of_secret(n: i32, delay: i32, forget: i32) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_2327() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.