C++ || O(N) || DP
\nclass Solution {\npublic:\n    \n    int countTexts(string s) {\n        \n        int mod=1000000007;\n        int n=s.length();\n        vector<long long> d
```\nclass Solution {\npublic:\n    \n    int countTexts(string s) {\n        \n        int mod=1000000007;\n        int n=s.length();\n        vector<long long> dp(n+1,1);\n        \n        for(int i=n-2;i>=0;i--)\n        {\n            if(s[i]==\'7\' || s[i]==\'9\')\n            {\n                //check for 4\n                long long ans=dp[i+1]; //1*dp[i+1]\n                int j=i+1;\n                int count=1;\n                while(j<n && s[j]==s[j-1] && count<4)\n                {\n                    count++;\n                    ans+=dp[j+1];\n                    ans%=mod;\n                    j++;\n                }\n                \n                dp[i]=ans;\n                \n            }\n            else\n            {\n                //check for 3\n                long long ans=dp[i+1]; //1*dp[i+1]\n                int j=i+1;\n                int count=1;\n                while(j<n && s[j]==s[j-1] && count<3)\n                {\n                    count++;\n                    ans+=dp[j+1];\n                    ans%=mod;\n                    j++;\n                }\n                \n                dp[i]=ans;\n                \n            }\n        }\n        \n        \n        \n        return dp[0];\n        \n    }\n};\n```
['Dynamic Programming', 'C']