Pythonic combinatorial exploration
Using itertool's product we can avoid doing the recursion or so many nested loops. We still have to take care of the valid hours tho.
Using itertool's `product` we can avoid doing the recursion or so many nested loops. We still have to take care of the valid hours tho.

```python3 []
class Solution:
    def countTime(self, time: str) -> int:
        h1, h2, _, m1, m2 = time
        digits = list(range(10))
        h1 = [int(h1)] if h1 != "?" else digits[:3]
        h2 = [int(h2)] if h2 != "?" else digits
        m1 = [int(m1)] if m1 != "?" else digits[:6]
        m2 = [int(m2)] if m2 != "?" else digits
        return sum(
            1
            for h in product(h1, h2)
            if h[0] * 10 + h[1] <= 23
            for m in product(m1, m2)
        )

```
['Python3']