def check_neighbor(y_coord, x_coord, visited, lowest, dist):
    """
    Checks if a given neighbor is valid
    """
    height, width = visited.shape
    return \
    y_coord < height and \
    y_coord >= 0 and \
    x_coord < width and \
    x_coord >= 0 and \
    visited[y_coord, x_coord] == 0 and \
    dist[y_coord, x_coord] < lowest and \
    dist[y_coord, x_coord] != 0