Python | DFS with Memoization | Groupby | O(n) | Easy to Read
```\nfrom functools import lru_cache\nfrom itertools import groupby\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        d = [0, 0, 3, 
```\nfrom functools import lru_cache\nfrom itertools import groupby\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        d = [0, 0, 3, 3, 3, 3, 3, 4, 3, 4]\n        M = 10**9+7\n        @lru_cache(None)\n        def dfs(i, k):\n            if i == 0: return 1\n            if i < 0: return 0\n            res = 0\n            for j in range(1,k+1):\n                res = (res + dfs(i-j, k))%M\n            return res\n        groups = [(int(k),len(list(v))) for k, v in groupby(pressedKeys)]\n        res = 1\n        for k, l in groups:\n            res = (res*dfs(l, d[k]))%M\n        return res
['Depth-First Search', 'Python']