Recursion+memorisation+hashmap
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    const int MOD = 1e9 + 7;
    int solve(int index,int length,int n,vector<int>& dp){
          if(index==n){
            return 1;
          }
          if(index>n){
            return 0;
          }
          if(dp[index]!=-1){
            return dp[index];
          }
          int ans=0;
          for(int i=1;i<=length;i++){
            ans=(ans+solve(index+i,length,n,dp))% MOD;
          }
          return dp[index]=ans;
    }
    int countTexts(string pressedKeys) {
       unordered_map<char,vector<int>> mp;
       char ch=pressedKeys[0];
       int count=0;
        for(int i=0;i<pressedKeys.size();i++){
            if(ch==pressedKeys[i]){
                count++;
            }
            else{
                mp[ch].push_back(count);
                ch=pressedKeys[i];
                count=1;
            }
        }
        mp[ch].push_back(count);
        int ans=1;
        for(auto p:mp){
           if(p.first=='7'||p.first=='9'){
             for(int i=0;i<p.second.size();i++){
                 vector<int> dp1(p.second[i],-1);
                  ans=(1LL * ans*solve(0,4,p.second[i],dp1))% MOD;
             }
           }
           else{
            for(int i=0;i<p.second.size();i++){
                vector<int> dp2(p.second[i],-1);
                  ans=(1LL * ans*solve(0,3,p.second[i],dp2))% MOD;
             }
           }
        }
        return ans;
    }
};
```
['C++']