/**
 * Given a dictionary 'artists' where each key represents an artist and
 * its value is a set of colors used by the artist, write a function
 * that returns a set of colors that are common to all artists.
 *
 * @param artists A dictionary where each key is an artist and its
 * value is a set of colors used by the artist.
 * @return A set of colors that are common to all artists.
 */
fun findCommonColors(artists: Map<String, Set<String>>): Set<String> {

    var commonColors = mutableSetOf<String>()

    // Iterate over each artist's color set
    for ((_, colors) in artists) {

        // Check if 'commonColors' set is empty, initializing it with the
        // artist's color set if it is empty
        if (commonColors.isEmpty()) {
            commonColors = colors.toMutableSet()
            continue
        }

        // Iterate over each common color and remove it if it is not present
        // in the current artist's color set
        val iterator = commonColors.iterator()
        while (iterator.hasNext()) {
            val color = iterator.next()
            if (color !in colors) {
                iterator.remove()
            }
        }
    }

    return commonColors
}
/**
 * Given a dictionary 'artists' where each key represents an artist and
 * its value is a set of colors used by the artist, write a function
 * that returns a set of colors that are common to all artists.
 *
 * @param artists A dictionary where each key is an artist and its
 * value is a set of colors used by the artist.
 * @return A set of colors that are common to all artists.
 */
fun findCommonColors(artists: Map<String, Set<String>>): Set<String> {
/**
 * Given a dictionary 'artists' where each key represents an artist and
 * its value is a set of colors used by the artist, write a function
 * that returns a set of colors that are common to all artists.
 *
 * @param artists A dictionary where each key is an artist and its
 * value is a set of colors used by the artist.
 * @return A set of colors that are common to all artists.
 */
fun findCommonColors(artists: Map<String, Set<String>>): Set<String> {

    var commonColors = mutableSetOf<String>()

    // Iterate over each artist's color set
    for ((_, colors) in artists) {

        // Check if 'commonColors' set is empty, initializing it with the
        // artist's color set if it is empty
        if (commonColors.isEmpty()) {
            commonColors = colors.toMutableSet()
            continue
        }

        // Iterate over each common color and remove it if it is not present
        // in the current artist's color set
        val iterator = commonColors.iterator()
        while (iterator.hasNext()) {
            val color = iterator.next()
            if (color !in colors) {
                iterator.remove()
            }
        }
    }

    return commonColors
}