C++ Intutive
\n\n\nclass Solution {\npublic:\n   \n    int countTexts(string pK) \n    {\n        int mod = 1e9+7;\n        \n        vector dp(pK.length()+1,1);\n        \n
\n\n\nclass Solution {\npublic:\n   \n    int countTexts(string pK) \n    {\n        int mod = 1e9+7;\n        \n        vector<int> dp(pK.length()+1,1);\n        \n        \n        for(int idx=pK.length()-1;idx>=0;idx--){\n            dp[idx] = dp[idx+1]%mod;\n        if(idx<pK.length()-1 and pK[idx+1]==pK[idx])\n        {\n        dp[idx]=(dp[idx]+dp[idx+2])%mod;\n        if(idx<pK.length()-2 and pK[idx+1]==pK[idx+2]) dp[idx]=(dp[idx]+dp[idx+3])%mod;\n        else continue;\n        if(idx<pK.length()-3 and pK[idx+2]==pK[idx+3] and (pK[idx]==\'7\'||pK[idx]==\'9\'))                             {dp[idx]=(dp[idx]+dp[idx+4])%mod;}\n        }\n        }\n         \n        return dp[0]%mod;\n    }\n};
['Dynamic Programming', 'Memoization']