Python 3 DP approach
IntuitionBy looking at the problem we can see a combination problem. We can start grouping the numbers and start creating patterns possible with that group by i
# Intuition
By looking at the problem we can see a combination problem. We can start grouping the numbers and start creating patterns possible with that group by increasing one element at a time. For Example:
i) 2 -> a
ii) 22-> aa, b
iii) 222 -> aaa, ab, ba, c
iV) 2222 -> aaaa, aab, aba, baa, bb, ac, ca

We can see this pattern where count(iv) = count(i) + count(ii) + count(iii)

From here we can think of a DP solution, similiar to a climbing stairs problem 

# Approach
Once we see it can be solved as a dp problem we need to find a recurrence relation which is 
dp[i]=dp[i−1], corresponding to taking the current key as a single press.

If pressedKeys[i−1]=pressedKeys[i−2], then dp[i]+=dp[i−2], considering two consecutive identical key presses.

If pressedKeys[i−1]=pressedKeys[i−2]=pressedKeys[i−3], then 
dp[i]+=dp[i−3], considering three consecutive identical key presses.

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(n)

# Code
```python3 []
class Solution:
    def countTexts(self, pressedKeys: str) -> int:
        dp = [0] * (len(pressedKeys)+1)

        # Only one way to interpret empty string
        dp[0] = 1

        # i+1 is the index of current element in dp array
        for i, c in enumerate(pressedKeys):
            # Pressed once case
            dp[i+1] = dp[i]
            
            # Pressed twice case
            if i and pressedKeys[i-1] == c: 
                dp[i+1] += dp[i-1]
                
                # Pressed thrice case
                if i >= 2 and pressedKeys[i-2] == c: 
                    dp[i+1] += dp[i-2]
                    
                    # Pressed 4 times case which is only possible in the case of 7 and 9
                    if i >= 3 and pressedKeys[i-3] == c:
                        if c in "79":
                            dp[i+1] += dp[i-3]
            
            # Store the remiander as it is the same thing as summing the dp array and then taking remainder
            dp[i+1] %= (10**9 + 7)
        
        return dp[-1]

        
```
['Python3']