/**
 * Given a list of countries, where each sublist represents the countries visited by an economist in a given trip,
 * return a set with the names of the countries that have been visited by the economist in all the trips.
 *
 * @param countries A list of lists of strings representing the countries visited in each trip.
 * @return A set of strings representing the countries visited in all the trips.
 *
 * Example:
 * findSharedCountries(listOf(listOf("Spain", "France", "Italy"), listOf("Spain", "Germany"), listOf("Spain", "Italy")))
 * Output: setOf("Spain")
 */
fun findSharedCountries(countries: List<List<String>>): Set<String> {

    // Initialize a set with the first sublist of countries
    var sharedCountries = countries[0].toSet()

    // Iterate over the remaining sublists of countries
    for (trip in countries.subList(1, countries.size)) {
        // Create a new set to store the countries visited in the current trip
        val currentCountries = trip.toSet()

        // Use set intersection to find the common countries between the previous trip and the current trip
        sharedCountries = sharedCountries.intersect(currentCountries)
    }

    return sharedCountries
}
/**
 * Given a list of countries, where each sublist represents the countries visited by an economist in a given trip,
 * return a set with the names of the countries that have been visited by the economist in all the trips.
 *
 * @param countries A list of lists of strings representing the countries visited in each trip.
 * @return A set of strings representing the countries visited in all the trips.
 *
 * Example:
 * findSharedCountries(listOf(listOf("Spain", "France", "Italy"), listOf("Spain", "Germany"), listOf("Spain", "Italy")))
 * Output: setOf("Spain")
 */
fun findSharedCountries(countries: List<List<String>>): Set<String> {
/**
 * Given a list of countries, where each sublist represents the countries visited by an economist in a given trip,
 * return a set with the names of the countries that have been visited by the economist in all the trips.
 *
 * @param countries A list of lists of strings representing the countries visited in each trip.
 * @return A set of strings representing the countries visited in all the trips.
 *
 * Example:
 * findSharedCountries(listOf(listOf("Spain", "France", "Italy"), listOf("Spain", "Germany"), listOf("Spain", "Italy")))
 * Output: setOf("Spain")
 */
fun findSharedCountries(countries: List<List<String>>): Set<String> {

    // Initialize a set with the first sublist of countries
    var sharedCountries = countries[0].toSet()

    // Iterate over the remaining sublists of countries
    for (trip in countries.subList(1, countries.size)) {
        // Create a new set to store the countries visited in the current trip
        val currentCountries = trip.toSet()

        // Use set intersection to find the common countries between the previous trip and the current trip
        sharedCountries = sharedCountries.intersect(currentCountries)
    }

    return sharedCountries
}