Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Number of People Aware of a Secret.cpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add problem No... at the first of the file name ....
nd the PR name should be also same as File name ...
as well as Star the repo ⭐

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also modify the PR description...

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int peopleAwareOfSecret(int n, int delay, int forget) {
vector<long long> dp(n + 1, 0);
dp[1] = 1;
long long share = 0, MOD = 1000000007;
for (int t = 2; t <= n; t++) {
if (t - delay > 0)
share = (share + dp[t - delay] + MOD) % MOD;
if (t - forget > 0)
share = (share - dp[t - forget] + MOD) % MOD;
dp[t] = share;
}
long long know = 0;
for (int i = n - forget + 1; i <= n; i++)
know = (know + dp[i]) % MOD;
return (int)know;
}
};