JAVA || From Recursion to Memoization to Tabulation || Easy-solution
Recursion -->>\n\n\nclass Solution {\n    int mod = (1000000007);\n\n    public int countTexts(String pressedKeys) {\n        int[] key = new int[] { 0, 0, 3, 3
Recursion -->>\n\n```\nclass Solution {\n    int mod = (1000000007);\n\n    public int countTexts(String pressedKeys) {\n        int[] key = new int[] { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4 };\n        int n = pressedKeys.length();\n        return solve(0,pressedKeys,key);\n    }\n\n    public int solve(int ind, String s, int[] key) {\n        if (ind == s.length()) {\n            return 1;\n        }\n        int count = 0;\n        int num = s.charAt(ind) - \'0\';\n        int rep = key[num];\n        for (int i = 0; i < rep && ind + i < s.length() && s.charAt(ind) == s.charAt(ind + i); i++) {\n            count += solve(ind + 1 + i, s, key);\n            count %= mod;\n        }\n        return  count;\n    }\n}\n```\n\nMemoization(Top-Down)-->>\n\n```\nclass Solution {\n    int mod = (1000000007);\n    public int countTexts(String pressedKeys) {\n         int[] key = new int[] {0,0,3,3,3,3,3,4,3,4};\n         int n = pressedKeys.length();\n         int[] dp = new int[n];\n        Arrays.fill(dp,-1);\n         return solve(0,pressedKeys,key,dp);\n    }\n    public int solve(int ind , String s ,int[] key,int[]dp){\n        if(ind==s.length()){\n            return 1;\n        }\n        if(dp[ind]!=-1) return dp[ind];\n        int count = 0;\n        int num = s.charAt(ind)-\'0\';\n        int rep = key[num];\n        for(int i =0;i<rep && ind+i<s.length() && s.charAt(ind)==s.charAt(ind+i);i++){\n            count += solve(ind+1+i,s,key,dp);\n            count %= mod;\n        }\n        return dp[ind] = count;\n    }\n}\n```\n\nTabulation(Bottom up)-->>\n```\nclass Solution {\n    int mod = (1000000007);\n\n    public int countTexts(String pressedKeys) {\n        int[] key = new int[] { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4 };\n        int n = pressedKeys.length();\n        int[] dp = new int[n + 1];\n        dp[n] = 1;\n\n        for (int ind = n - 1; ind >= 0; ind--) {\n            int count = 0;\n            int num = pressedKeys.charAt(ind) - \'0\';\n            int rep = key[num];\n            for (int i = 0; i < rep && ind + i < pressedKeys.length() && pressedKeys.charAt(ind) == pressedKeys.charAt(ind + i); i++) {\n                count += dp[ind+i+1];\n                count %= mod;\n            }\n             dp[ind] = count;\n        }\n        return dp[0];\n    }\n}\n```\n\nDo Upvote if you find these solution Helpful.
['Dynamic Programming', 'Recursion', 'Memoization', 'Java']