/**
 * Given a list of connections and two indices, this function checks if there is a faulty connection
 * between the specified indices. It returns the index of the first faulty connection found or -1 if
 * no faulty connection is detected.
 *
 * @param connections A list of strings representing the connections.
 * @param index1 An integer representing the first index.
 * @param index2 An integer representing the second index.
 * @return An integer representing the index of the first faulty connection found, or -1 if no faulty
 * connection is detected.
 */
fun findFaultyConnection(connections: List<String>, index1: Int, index2: Int): Int {

    return connections.subList(index1, index2).indexOfFirst { it.contains("?") }.let { if (it == -1) -1 else it + index1 }
}
/**
 * Given a list of connections and two indices, this function checks if there is a faulty connection
 * between the specified indices. It returns the index of the first faulty connection found or -1 if
 * no faulty connection is detected.
 *
 * @param connections A list of strings representing the connections.
 * @param index1 An integer representing the first index.
 * @param index2 An integer representing the second index.
 * @return An integer representing the index of the first faulty connection found, or -1 if no faulty
 * connection is detected.
 */
fun findFaultyConnection(connections: List<String>, index1: Int, index2: Int): Int {
/**
 * Given a list of connections and two indices, this function checks if there is a faulty connection
 * between the specified indices. It returns the index of the first faulty connection found or -1 if
 * no faulty connection is detected.
 *
 * @param connections A list of strings representing the connections.
 * @param index1 An integer representing the first index.
 * @param index2 An integer representing the second index.
 * @return An integer representing the index of the first faulty connection found, or -1 if no faulty
 * connection is detected.
 */
fun findFaultyConnection(connections: List<String>, index1: Int, index2: Int): Int {

    return connections.subList(index1, index2).indexOfFirst { it.contains("?") }.let { if (it == -1) -1 else it + index1 }
}