/**
 * This function takes in a list of pets and a map of veterinarian records,
 * and returns a list of treats that are common to all pets seen by the veterinarian.
 *
 * @param pets a list of pets (strings) seen by the veterinarian
 * @param vetRecords a map with veterinarian records where the keys represent
 *                   pets and the values are lists of treats given to the corresponding pet
 * @return a list of treats (strings) that are common to all pets seen by the veterinarian
 *
 * Example:
 * findCommonTreats(listOf("Fluffy", "Max", "Charlie"), mapOf("Fluffy" to listOf("Bone", "Tuna"),
 *                                                           "Max" to listOf("Fish", "Bone", "Tuna"),
 *                                                           "Charlie" to listOf("Fish", "Bone")))
 * Output:
 * ["Bone"]
 */
fun findCommonTreats(pets: List<String>, vetRecords: Map<String, List<String>>): List<String> {

    if (pets.isEmpty()) {
        return emptyList()
    }

    var commonTreats = vetRecords[pets[0]] ?: emptyList()

    for (pet in pets.drop(1)) {
        val currentTreats = vetRecords[pet] ?: emptyList()
        commonTreats = commonTreats.filter { treat -> currentTreats.contains(treat) }
    }

    return commonTreats
}
/**
 * This function takes in a list of pets and a map of veterinarian records,
 * and returns a list of treats that are common to all pets seen by the veterinarian.
 *
 * @param pets a list of pets (strings) seen by the veterinarian
 * @param vetRecords a map with veterinarian records where the keys represent
 *                   pets and the values are lists of treats given to the corresponding pet
 * @return a list of treats (strings) that are common to all pets seen by the veterinarian
 *
 * Example:
 * findCommonTreats(listOf("Fluffy", "Max", "Charlie"), mapOf("Fluffy" to listOf("Bone", "Tuna"),
 *                                                           "Max" to listOf("Fish", "Bone", "Tuna"),
 *                                                           "Charlie" to listOf("Fish", "Bone")))
 * Output:
 * ["Bone"]
 */
fun findCommonTreats(pets: List<String>, vetRecords: Map<String, List<String>>): List<String> {
/**
 * This function takes in a list of pets and a map of veterinarian records,
 * and returns a list of treats that are common to all pets seen by the veterinarian.
 *
 * @param pets a list of pets (strings) seen by the veterinarian
 * @param vetRecords a map with veterinarian records where the keys represent
 *                   pets and the values are lists of treats given to the corresponding pet
 * @return a list of treats (strings) that are common to all pets seen by the veterinarian
 *
 * Example:
 * findCommonTreats(listOf("Fluffy", "Max", "Charlie"), mapOf("Fluffy" to listOf("Bone", "Tuna"),
 *                                                           "Max" to listOf("Fish", "Bone", "Tuna"),
 *                                                           "Charlie" to listOf("Fish", "Bone")))
 * Output:
 * ["Bone"]
 */
fun findCommonTreats(pets: List<String>, vetRecords: Map<String, List<String>>): List<String> {

    if (pets.isEmpty()) {
        return emptyList()
    }

    var commonTreats = vetRecords[pets[0]] ?: emptyList()

    for (pet in pets.drop(1)) {
        val currentTreats = vetRecords[pet] ?: emptyList()
        commonTreats = commonTreats.filter { treat -> currentTreats.contains(treat) }
    }

    return commonTreats
}