Time: 3 ms (85.71%), Space: 12.6 MB (40%) - LeetHub

This commit is contained in:
Deven
2025-09-09 15:00:20 -04:00
parent 985576ef90
commit efb67806a5
@@ -0,0 +1,26 @@
class Solution(object):
def peopleAwareOfSecret(self, n, delay, forget):
"""
:type n: int
:type delay: int
:type forget: int
:rtype: int
"""
new = [0] * forget
new[0] = 1
total_known = 1
cant_tell = 1
for i in range(1, n):
index = i % forget
forget_index = index
delay_index = (i - delay + forget) % forget
total_known -= new[forget_index]
cant_tell -= new[delay_index]
new[index] = total_known - cant_tell
cant_tell += new[index]
total_known += new[index]
return total_known % (10 ** 9 + 7)