/**
 * You are a musician with a list of other musicians. Each musician has a list of their favorite songs.
 * Your task is to find all the songs that are favorites of at least two musicians.
 *
 * Complete the code below to solve the exercise.
 */
fun findFavoriteSongs(musicians: List<Map<String, List<String>>>): List<String> {

    val favoriteSongs = mutableListOf<String>()

    for (musician in musicians) {
        for (song in musician["favorite_songs"]!!) {
            var count = 0

            // Loop through all musicians again to check if the current song is also their favorite
            for (otherMusician in musicians) {
                if (otherMusician != musician && song in otherMusician["favorite_songs"]!!) {
                    count++
                }
            }

            if (count >= 2 && song !in favoriteSongs) {
                favoriteSongs.add(song)
            }
        }
    }

    return favoriteSongs
}
/**
 * You are a musician with a list of other musicians. Each musician has a list of their favorite songs.
 * Your task is to find all the songs that are favorites of at least two musicians.
 *
 * Complete the code below to solve the exercise.
 */
fun findFavoriteSongs(musicians: List<Map<String, List<String>>>): List<String> {
/**
 * You are a musician with a list of other musicians. Each musician has a list of their favorite songs.
 * Your task is to find all the songs that are favorites of at least two musicians.
 *
 * Complete the code below to solve the exercise.
 */
fun findFavoriteSongs(musicians: List<Map<String, List<String>>>): List<String> {

    val favoriteSongs = mutableListOf<String>()

    for (musician in musicians) {
        for (song in musician["favorite_songs"]!!) {
            var count = 0

            // Loop through all musicians again to check if the current song is also their favorite
            for (otherMusician in musicians) {
                if (otherMusician != musician && song in otherMusician["favorite_songs"]!!) {
                    count++
                }
            }

            if (count >= 2 && song !in favoriteSongs) {
                favoriteSongs.add(song)
            }
        }
    }

    return favoriteSongs
}