/**
 * Given a dictionary of actors and their corresponding movies, find the movies that
 * intersect between the given actor and all other actors in the dictionary.
 *
 * @param actorsDict A dictionary containing actors as keys and their movies as values.
 * @param targetActor The actor for which we want to find the intersection of movies.
 * @return A set of movies that intersect between the target actor and all other actors in the dictionary.
 */
fun findIntersection(actorsDict: Map<String, List<String>>, targetActor: String): Set<String>? {

    var intersection: Set<String>? = null

    if (targetActor in actorsDict) {
        intersection = actorsDict[targetActor]?.toSet()
        val actors = actorsDict.keys.toList()

        for (actor in actors) {
            if (actor == targetActor) {
                continue
            }

            val intersectingMovies = actorsDict[actor]?.toSet()
            intersection = intersection?.intersect(intersectingMovies ?: emptySet())

            if (intersection?.isEmpty() == true) {
                intersection = null
                break
            }
        }
    }

    return intersection
}
/**
 * Given a dictionary of actors and their corresponding movies, find the movies that
 * intersect between the given actor and all other actors in the dictionary.
 *
 * @param actorsDict A dictionary containing actors as keys and their movies as values.
 * @param targetActor The actor for which we want to find the intersection of movies.
 * @return A set of movies that intersect between the target actor and all other actors in the dictionary.
 */
fun findIntersection(actorsDict: Map<String, List<String>>, targetActor: String): Set<String>? {
/**
 * Given a dictionary of actors and their corresponding movies, find the movies that
 * intersect between the given actor and all other actors in the dictionary.
 *
 * @param actorsDict A dictionary containing actors as keys and their movies as values.
 * @param targetActor The actor for which we want to find the intersection of movies.
 * @return A set of movies that intersect between the target actor and all other actors in the dictionary.
 */
fun findIntersection(actorsDict: Map<String, List<String>>, targetActor: String): Set<String>? {

    var intersection: Set<String>? = null

    if (targetActor in actorsDict) {
        intersection = actorsDict[targetActor]?.toSet()
        val actors = actorsDict.keys.toList()

        for (actor in actors) {
            if (actor == targetActor) {
                continue
            }

            val intersectingMovies = actorsDict[actor]?.toSet()
            intersection = intersection?.intersect(intersectingMovies ?: emptySet())

            if (intersection?.isEmpty() == true) {
                intersection = null
                break
            }
        }
    }

    return intersection
}