Skip to content
LC-2327 Medium LeetCode

2327. Number of People Aware of a Secret

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 46% Topics: Dynamic Programming, Queue, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(f)

# dp
class Solution(object):
    def peopleAwareOfSecret(self, n, delay, forget):
        """
        :type n: int
        :type delay: int
        :type forget: int
        :rtype: int
        """
        MOD = 10**9+7
        dp = [0]*forget
        dp[0] = 1
        for i in xrange(1, n):
            dp[i%forget] = ((dp[(i-1)%forget] if i-1 else 0)-dp[i%forget]+dp[(i-delay)%forget]) % MOD
        return sum(dp)%MOD

Solution from kamyu104/LeetCode-Solutions · MIT