Simple Memoization technique | O(N)
Intuition: If the pressedString is "222", there can 3 different keys pressed: \'a\'("2"), \'b\'("22") or \'c\'("222"). So for every repeated keys, there can be 
**Intuition:** If the pressedString is "222", there can 3 different keys pressed: \'a\'("2"), \'b\'("22") or \'c\'("222"). So for every repeated keys, there can be multiple combinations of texts. We store the max repeatations of a particular key in keys array, and then try all recursive paths to get the count of several combinations of keys that can be formed starting from a particular index. As we try all recursive paths, so there has to be many repeated calculations, which can be mitigated by memoisation.\n\n```\nCode:\nclass Solution {\npublic:\n    static const int mod = 1e9+7;\n    int dp[100001];\n    static constexpr int keys[10] = {0,0,3,3,3,3,3,4,3,4};  // key \'1\' and \'0\' not to be used\n    int countTexts(string pressedKeys) {\n        memset(dp, -1, sizeof(dp));\n        return getCounts(pressedKeys, 0);\n    }\n    \n    int getCounts(string &pressed, int idx) {\n        if(idx == pressed.length())\n            return 1;\n        if(dp[idx] != -1)\n            return dp[idx];\n        int digit = pressed[idx]-\'0\'; long counts = 0;\n        for(int i = 0; i < keys[digit] && idx+i < pressed.length() && pressed[idx] == pressed[idx+i]; i++) {\n            counts += getCounts(pressed, idx+i+1);\n            counts %= mod;\n        }\n        return dp[idx] = counts;\n    }\n};\n```\nKindly upvote if helpful to keep me motivated ^-^. Also comment down for any doubts.\n
['Dynamic Programming', 'Memoization']