Very detailed recursive tree diagram with decent intuition {C++ memorized code}
Count Number of Texts\n\nIntuition\n As we know in feature phones, numbers (2, 3, 4, 5, 6, 8) have maximum 3 characters while (7 and 9) have 4 characters.\n So 
# Count Number of Texts\n\n***Intuition***\n* As we know in feature phones, numbers (2, 3, 4, 5, 6, 8) have maximum 3 characters while (7 and 9) have 4 characters.\n* So if we encountered same key press again in input then we have 2 choices either we can take it as single key press (take 1st letter of that pressed number) and move on or we can say that  a previously pressed number tapped again (if a same key pressed again then we take the next letter which is embedded to that number key).\n***Example***\n\t* Let\'s say we have input "22223"\n       * if we consider every number was pressed once then the output word would be "aaaad".\n       * if we consider that 2 was pressed twice at same time then the output word would be "baac".\n       * if we say 2 pressed thrice then, we\'ll get "cab" as the output\n       * (**note**) This time we can\'t take four 2s at same time because we know, we can only get a letter from number key 2 when it gets pressed once (a), twice(b) & thrice(c). Therefore the 4th keypress (2) considered as first tap & the keypress gives \'a\'.\n  * **Please refer to the below recursive tree diagram for better understanding.**\n<br>\n![image](https://assets.leetcode.com/users/images/54f19f39-f2f0-463c-bec7-148f134327c0_1654338912.543673.png)\n\n***Please Upvote if you like the post*** \u2B06\uFE0F\n\n**Recursion [TLE]**\n\n```\nclass Solution {\npublic:\n    int mod = 1e9+7;\n    int solve(string &str, int idx) {\n        if(idx == str.length()) return 1;\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 ans%mod;\n    }\n    int countTexts(string pressedKeys) {\n        return solve(pressedKeys, 0) % mod;\n    }\n};\n```\n\n**Recursion + Memoization [#ACCEPTED]**\n*TC : O(N) & SC: O(N), where N is input string length*\n\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```\n\nThanks to [@aman-Raj](https://leetcode.com/aman-raj/) & [@anishakd](https://leetcode.com/anishakd/) for helping in recursive tree diagram \u2764\uFE0F.
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']