def check_visibility(line: str) -> bool:
    """
    Check visibility for a given line of houses from both sides.

    >>> check_visibility('412354*')
    True
    >>> check_visibility('4123542')
    True
    >>> check_visibility('312354*')
    False
    >>> check_visibility('3123545')
    False
    >>> check_visibility('*12354*')
    True
    >>> check_visibility('*125342')
    True
    """
    heights = list(map(int, line[1:-1]))

    # check visibility for leftmost hint
    if line[0] != '*':
        idx = 0
        count = 0
        curr_max = float('-inf')

        while idx < len(heights):
            if heights[idx] > curr_max:
                count += 1
                curr_max = heights[idx]

            idx += 1

        if count != int(line[0]):
            return False

    # check visibility for rightmost hint
    if line[-1] != '*':
        idx = len(heights) - 1
        count = 0
        curr_max = float('-inf')

        while idx >= 0:
            if heights[idx] > curr_max:
                count += 1
                curr_max = heights[idx]

            idx -= 1

        if count != int(line[-1]):
            return False

    return True