Problem: Number of Valid Clock Times

You are given a string of length `5` called `time`, representing the current
time on a digital clock in the format `"hh:mm"`. The earliest possible time is
`"00:00"` and the latest possible time is `"23:59"`.

In the string `time`, the digits represented by the `?` symbol are unknown,
and must be replaced with a digit from `0` to `9`.

Return an integer `answer`, the number of valid clock times that can be
created by replacing every `?` with a digit from `0` to `9`.


Python solution:
import math
import itertools
import bisect
import collections
import string
import heapq
import functools
import sortedcontainers
from typing import List, Dict, Tuple, Iterator

class Solution:
  def countTime(self, time: str) -> int:
    ans = 1
    if time[3] == '?':
      ans *= 6
    if time[4] == '?':
      ans *= 10

    if time[0] == '?' and time[1] == '?':
      return ans * 24
    if time[0] == '?':
      if time[1] < '4':
        return ans * 3
      else:
        return ans * 2
    if time[1] == '?':
      if time[0] == '2':
        return ans * 4
      else:
        return ans * 10
    return ans


Java solution:
class Solution {
  public int countTime(String time) {
    int ans = 1;
    if (time.charAt(3) == '?')
      ans *= 6;
    if (time.charAt(4) == '?')
      ans *= 10;

    if (time.charAt(0) == '?' && time.charAt(1) == '?')
      return ans * 24;
    if (time.charAt(0) == '?')
      return time.charAt(1) < '4' ? ans * 3 : ans * 2;
    if (time.charAt(1) == '?')
      return time.charAt(0) == '2' ? ans * 4 : ans * 10;
    return ans;
  }
}


C++ solution:
class Solution {
 public:
  int countTime(string time) {
    int ans = 1;
    if (time[3] == '?')
      ans *= 6;
    if (time[4] == '?')
      ans *= 10;

    if (time[0] == '?' && time[1] == '?')
      return ans * 24;
    if (time[0] == '?')
      return time[1] < '4' ? ans * 3 : ans * 2;
    if (time[1] == '?')
      return time[0] == '2' ? ans * 4 : ans * 10;
    return ans;
  }
};