Java | DP | Simple
```\n\tpublic int countTexts(String pk) {\n        long[] _3digits = new long[]{1, 2, 4, 7};\n        long[] _4digits = new long[]{1, 2, 4, 8};\n        int n =
```\n\tpublic int countTexts(String pk) {\n        long[] _3digits = new long[]{1, 2, 4, 7};\n        long[] _4digits = new long[]{1, 2, 4, 8};\n        int n = pk.length();\n        char ch = pk.charAt(0);\n        int count = 1;\n        long res = 1;\n        long[] toAdd = (ch == \'7\' || ch == \'9\')? _4digits : _3digits;\n        List<Long> freq = Arrays.stream(toAdd).boxed().collect(Collectors.toList());\n        int modulo = 1000000007;\n        \n        for(int i=1; i<n; i++) {\n            if (pk.charAt(i) == ch) {\n                count++;\n                if (count > 4) {\n                    long newCount = (freq.get(count - 2) + freq.get(count - 3) + freq.get(count - 4)) % modulo;\n                    newCount = (ch == \'7\' || ch == \'9\')? (newCount + freq.get(count - 5))%modulo : newCount;\n                    freq.add(newCount);\n                }\n            }else{\n                res = (res * freq.get(count - 1)) % modulo;\n                \n                ch = pk.charAt(i);\n                toAdd = (ch == \'7\' || ch == \'9\')? _4digits : _3digits;\n                freq = Arrays.stream(toAdd).boxed().collect(Collectors.toList());\n                count = 1;\n            }\n        }\n        \n        res = (res * freq.get(count - 1)) % modulo;\n        return (int) res;\n\t}
['Dynamic Programming', 'Java']