Python Sliding Window O(1) Space
\nfrom collections import deque\n\n\nclass Solution:\n    \n    def countTexts(self, pressed_keys: str) -> int:\n        \n        key_letters = {\n            
```\nfrom collections import deque\n\n\nclass Solution:\n    \n    def countTexts(self, pressed_keys: str) -> int:\n        \n        key_letters = {\n            "2": 3,\n            "3": 3,\n            "4": 3,\n            "5": 3,\n            "6": 3,\n            "7": 4,\n            "8": 3,\n            "9": 4,\n        }\n        \n        ans = 1\n        current_count = 1\n        prev_key = "" \n        previous = deque([]) \n        \n        for pressed_key in pressed_keys:\n            \n            if pressed_key != prev_key:\n                ans = (ans * current_count) % (10**9 + 7)\n                previous = deque([1])\n                current_count = 1 \n                prev_key = pressed_key\n            \n            current_count = sum(previous) \n            \n            if len(previous) == key_letters[pressed_key]:\n                previous.popleft()\n                \n            previous.append(current_count)\n             \n        ans = (ans * current_count) % (10**9 + 7)\n        \n        return ans\n    \n```
[]