/**
 * This function finds the common pets among two lists of animals.
 *
 * @param animals1 A list of animals the veterinarian has treated.
 * @param animals2 Another list of animals the veterinarian has treated.
 * @return A set of animals that are common in both lists.
 */
fun commonPets(animals1: List<String>, animals2: List<String>): Set<String> {

    // Find the unique animals from each list
    val uniqueAnimals1 = animals1.toSet()
    val uniqueAnimals2 = animals2.toSet()

    // Find the common animals by taking the intersection of the sets
    val commonAnimals = uniqueAnimals1.intersect(uniqueAnimals2).toMutableSet()

    // Remove the pets that are not equal to each other
    uniqueAnimals1.forEach { animal ->
        if (animal !in uniqueAnimals2) {
            commonAnimals.remove(animal)
        }
    }

    return commonAnimals
}
/**
 * This function finds the common pets among two lists of animals.
 *
 * @param animals1 A list of animals the veterinarian has treated.
 * @param animals2 Another list of animals the veterinarian has treated.
 * @return A set of animals that are common in both lists.
 */
fun commonPets(animals1: List<String>, animals2: List<String>): Set<String> {
/**
 * This function finds the common pets among two lists of animals.
 *
 * @param animals1 A list of animals the veterinarian has treated.
 * @param animals2 Another list of animals the veterinarian has treated.
 * @return A set of animals that are common in both lists.
 */
fun commonPets(animals1: List<String>, animals2: List<String>): Set<String> {

    // Find the unique animals from each list
    val uniqueAnimals1 = animals1.toSet()
    val uniqueAnimals2 = animals2.toSet()

    // Find the common animals by taking the intersection of the sets
    val commonAnimals = uniqueAnimals1.intersect(uniqueAnimals2).toMutableSet()

    // Remove the pets that are not equal to each other
    uniqueAnimals1.forEach { animal ->
        if (animal !in uniqueAnimals2) {
            commonAnimals.remove(animal)
        }
    }

    return commonAnimals
}