Simple O(N) single pass solution
For every number other than 7 and 9, we can consider at most 3 consecutive digits whereas for 7 and 9 we can consider atmost 4 consecutive digits.\n\nLogic:\n- 
For every number other than 7 and 9, we can consider at most 3 **consecutive** digits whereas for 7 and 9 we can consider atmost 4 **consecutive** digits.\n\nLogic:\n- Make an empty dp array.\n- Iterate through every key pressed in pressedKeys and for every **i** we can add dp[i-1],dp[i-2],dp[i-3] to dp[i] and if pressedKeys[i] is either 7 or 9 then we can add dp[i-4] also.\n- <img src="https://assets.leetcode.com/users/images/9a4f16ea-9965-4fa6-91a4-b2e3e5629139_1651982047.43855.jpeg" width=450 height=400 align=center>\n\nCode:\n```\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        MOD=pow(10,9)+7\n        dp=[0]*(len(pressedKeys)+1)\n        dp[0]=1\n        for i in range(1,len(pressedKeys)+1):\n            dp[i]=dp[i-1]%MOD\n            if(i-2>=0 and pressedKeys[i-1]==pressedKeys[i-2]):\n                dp[i]=(dp[i]+dp[i-2])%MOD\n                if(i-3>=0 and pressedKeys[i-1]==pressedKeys[i-3]):\n                    dp[i]=(dp[i]+dp[i-3])%MOD\n                    if(pressedKeys[i-1] in "79" and i-4>=0 and pressedKeys[i-1]==pressedKeys[i-4]):\n                        dp[i]=(dp[i]+dp[i-4])%MOD\n        return dp[-1]\n```
[]