c++ | easy | recursion &  DP
\n# Code\n\nclass Solution {\npublic:\n   int dp[100005];\n    int mod = 1e9+7;\n    int solve(string &str, int idx) {\n        if(idx == str.length()) return 1
\n# Code\n```\nclass Solution {\npublic:\n   int dp[100005];\n    int mod = 1e9+7;\n    int solve(string &str, int idx) {\n        if(idx == str.length()) return 1;\n        if(dp[idx] != -1) return dp[idx];\n        int maxKeyPress = (str[idx] == \'7\' || str[idx] == \'9\') ? 4 : 3;\n        long long currIndex = idx, pressFrequency = 1, ans = 0;\n        while(pressFrequency <= maxKeyPress && str[currIndex] == str[idx]) {\n            ++currIndex;\n            ++pressFrequency;\n            ans += solve(str, currIndex) % mod;\n        }\n        return dp[idx] = ans%mod;\n    }\n    int countTexts(string pressedKeys) {\n        memset(dp, -1, sizeof(dp));\n        return solve(pressedKeys, 0) % mod;\n    }\n};\n```
['C++']