/**
 * Find the intersection of nested sets using slicing.
 *
 * Given a list of nested sets, the function finds the common elements among them using slicing technique.
 *
 * @param nestedSet A list containing nested sets.
 * @return A list containing the intersection of nested sets.
 *
 * Example:
 * findIntersection(listOf(listOf(1, 2, 3), listOf(2, 3, 4), listOf(3, 4, 5))) // [3]
 * findIntersection(listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))) // []
 *
 * Note:
 * - The input nestedSet will always contain at least one nested set.
 * - All elements within the nested sets will be unique.
 * - The returned intersection list should not contain any duplicates.
 */
fun findIntersection(nestedSet: List<List<Int>>): List<Int> {

    var intersection = nestedSet[0].toSet()

    // Iterate through each nested set
    for (nested in nestedSet.subList(1, nestedSet.size)) {
        // Take the intersection of the current nested set and the existing intersection
        intersection = intersection.intersect(nested.toSet())
    }

    return intersection.toList()
}
/**
 * Find the intersection of nested sets using slicing.
 *
 * Given a list of nested sets, the function finds the common elements among them using slicing technique.
 *
 * @param nestedSet A list containing nested sets.
 * @return A list containing the intersection of nested sets.
 *
 * Example:
 * findIntersection(listOf(listOf(1, 2, 3), listOf(2, 3, 4), listOf(3, 4, 5))) // [3]
 * findIntersection(listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))) // []
 *
 * Note:
 * - The input nestedSet will always contain at least one nested set.
 * - All elements within the nested sets will be unique.
 * - The returned intersection list should not contain any duplicates.
 */
fun findIntersection(nestedSet: List<List<Int>>): List<Int> {
/**
 * Find the intersection of nested sets using slicing.
 *
 * Given a list of nested sets, the function finds the common elements among them using slicing technique.
 *
 * @param nestedSet A list containing nested sets.
 * @return A list containing the intersection of nested sets.
 *
 * Example:
 * findIntersection(listOf(listOf(1, 2, 3), listOf(2, 3, 4), listOf(3, 4, 5))) // [3]
 * findIntersection(listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))) // []
 *
 * Note:
 * - The input nestedSet will always contain at least one nested set.
 * - All elements within the nested sets will be unique.
 * - The returned intersection list should not contain any duplicates.
 */
fun findIntersection(nestedSet: List<List<Int>>): List<Int> {

    var intersection = nestedSet[0].toSet()

    // Iterate through each nested set
    for (nested in nestedSet.subList(1, nestedSet.size)) {
        // Take the intersection of the current nested set and the existing intersection
        intersection = intersection.intersect(nested.toSet())
    }

    return intersection.toList()
}