940. Distinct Subsequences II

class Solution:
    def distinctSubseqII(self, s: str) -> int:
        
        seq = [0] * 26
        MOD = 10 ** 9 + 7

        total = 1

        for i in range(len(s)):
            # Minus the seq to remove the repetition 
            # Since seq[s[i]] number of subsequence are used to compute the 
            # previous s[i] letter
            new = total - seq[ord(s[i]) - ord('a')] % MOD
            total += new
            seq[ord(s[i]) - ord('a')] += new

        return (total - 1)  % MOD