tabulation with constant space
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 {
    int mod = 1e9 + 7;

public:
    int countTexts(string keys) {

        vector<int> dp(4, 0);
        dp[0] = 1;

        for (int start = keys.size() - 1; start >= 0; start--) {

            int next = 0;
            int k = 3 + (keys[start] == '7' || keys[start] == '9');

            for (int i = start; i < keys.size() && k > 0; i++) {

                if (i != start && keys[i] != keys[i - 1])
                    break;

                int val = 0;
                if (keys[start] == '7' || keys[start] == '9') {
                    val = dp[4 - k];
                } else {
                    val = dp[3 - k];
                }
                next = (next + val) % mod;
                k--;
            }

            dp = {next, dp[0], dp[1], dp[2]};
        }

        return dp[0];
    }
};
```
['C++']