Intuitive Python Solution (O(N), beats 97%)
Code\n\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        ans = 1\n        modulo = 10 ** 9 + 7\n        \n        # Sequences of dig
# Code\n```\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        ans = 1\n        modulo = 10 ** 9 + 7\n        \n        # Sequences of digits with 3 & 4 letters\n        seqs = {3: [], 4: []}\n        \n        # DP for basic cases\n        dp = {\n            3: [1, 2, 4],  # Keys with 3 letters (2, 3, 4, 5, 6, 8)\n            4: [1, 2, 4, 8]  # Keys with 4 letters (7, 9)\n        }\n        \n        # Append and store sequences of 7 and 9 separately\n        def appendSeq(key):\n            seqs[4 if key in {\'7\', \'9\'} else 3].append(curSeq)\n\n        # Iterate the pressed keys and store the length of each subsequence\n        curSeq, curKey = 1, pressedKeys[0]\n        for key in pressedKeys[1:]:\n            if not curKey == key:\n                appendSeq(curKey)\n                curKey, curSeq = key, 0\n            curSeq += 1\n        appendSeq(curKey)\n        \n        for k in seqs.keys():\n            # Update the DP with new sequences (only consider the maximum seqeunce length)\n            if seqs[k]:\n                for i in range(k, max(seqs[k])):\n                    dp[k].append(sum(dp[k][(i - k):i]) % modulo)\n\n            # Update the final result using DP & given modulo\n            for seq in seqs[k]:\n                ans *= dp[k][seq - 1]\n                ans %= modulo\n\n        return ans\n```
['Dynamic Programming', 'Python3']