DP | TABULATION | OBSERVATION
PLEASE UPVOTE IF U FIND MY SOLUTION HELPFUL\n\n\n#define ll long long\nclass Solution \n{\n    const int M=1e9+7;\npublic:\n    int countTexts(string pK) \n    
**PLEASE UPVOTE IF U FIND MY SOLUTION HELPFUL**\n\n```\n#define ll long long\nclass Solution \n{\n    const int M=1e9+7;\npublic:\n    int countTexts(string pK) \n    {\n        vector<pair<char,int>>v;\n        int len=pK.length();\n        \n        int maxx=0;\n        bool has_7OR9=0;//optimisation\n        for(int i=0;i<len;)\n        {\n            char ch=pK[i];\n            int c=0;\n            while(i<len&&pK[i]==ch)\n            {\n                c++;\n                i++;\n            }\n            maxx=max(maxx,c);\n            if(ch==\'7\'||ch==\'9\')\n                has_7OR9=1;\n            v.push_back({ch,c});\n        }\n        \n        \n        maxx=max(4,maxx);\n        vector<ll>dp1(maxx+1,0);//storing characters other than 7 and 9\n        vector<ll>dp2(maxx+1,0);//storing characters 7 and 9\n        dp1[1]=1,dp1[2]=2,dp1[3]=4;\n        dp2[1]=1,dp2[2]=2,dp2[3]=4,dp2[4]=8;\n        \n        for(int i=4;i<=maxx;i++)\n        {\n            dp1[i]=(dp1[i-1]+dp1[i-2]+dp1[i-3])%M;\n        }\n        \n        //not necessary but okie \n        if(has_7OR9)\n        {\n           for(int i=5;i<=maxx;i++)\n        {\n            dp2[i]=(dp2[i-1]%M+dp2[i-2]%M+dp2[i-3]%M+dp2[i-4]%M)%M;\n        }  \n        }\n       \n        ll res=1;\n        for(auto [ch,c]:v)\n        {\n        if(ch==\'7\'||ch==\'9\')\n        {\n              res=(res*(dp2[c])%M)%M;\n        }\n        else\n        {\n              res=(res*(dp1[c])%M)%M;\n        }\n        }\n        \n        return res;\n    }\n};\n\n\n```
['Dynamic Programming']