JAVA --- TABULATION
\nclass Solution {\n    public static int[] press = {0, 0, 3, 3, 3, 3, 3, 4, 3, 4};\n    int mod = 1000000007;\n    public int countTexts(String pressedKeys) {\
```\nclass Solution {\n    public static int[] press = {0, 0, 3, 3, 3, 3, 3, 4, 3, 4};\n    int mod = 1000000007;\n    public int countTexts(String pressedKeys) {\n        int[] dp = new int[pressedKeys.length()];\n        dp[0] = 1;\n        int freq = 1;\n        \n        for(int i=1;i<pressedKeys.length();i++){\n            char ch = pressedKeys.charAt(i);\n            if(i==0 || ch!=pressedKeys.charAt(i-1)){\n                freq = 1;\n            } else {\n                freq++;\n            }\n            \n            for(int j=1;j<=Math.min(freq, press[ch-\'0\']);j++){\n                dp[i] += ( (i - j == -1) ? 1 : dp[i - j] );\n                dp[i] %= mod;\n            }\n        }\n        \n        return dp[dp.length-1];\n    }\n}\n```\n\n# Notes :- \n\n1. freq denotes the possible amount of times a key can be pressed. For instance, in the message "222", the third \'2\' can either be pressed once to type \'a\', or twice to type \'b\' or thrice simultaneously to type \'c\'. \n2. Math.min(freq, press[ch-\'0\']) is necessary. For instance, in the message "2222", there is no mapping for all 2\'s being pressed simultaneously. The 4rth 2 was either pressed once to type \'a\', or twice alongwith 3rd \'2\' to type \'b\' or thrice alongwith 2nd and 3rd \'2\' to type \'c\'. The \'min\' part will ensure that the simultaneous presses of a digit doesn\'t exceed the allowed maximum simultaneous press for that digit.\n3. The ( i - j == -1) part only makes sense if first 2 digits are the same, just to escape from "Array Out Of Bounds Exception".\n\n* Time Complexity :- O(4*N) => O(N)\n* Space Complexity :- O(N)\n\nHope you found the solution and the notes insightful !
['Dynamic Programming', 'Java']