/**
 * This exercise aims to find the common elements in a nested list and return them as a list.
 * The input to this function is a list of lists, where each nested list represents a group of elements.
 * The function should find the elements that appear in all the nested lists and return them as a list.
 *
 * Example:
 * findCommonElements(listOf(listOf(1, 2, 3), listOf(4, 2, 5), listOf(2, 7, 8, 9))) should return [2].
 */
fun findCommonElements(lists: List<List<Int>>): List<Int> {

    var commonElements = lists[0].toMutableList() // Assume the first list as the initial reference

    for (sublist in lists.subList(1, lists.size)) { // Iterate through the remaining nested lists
        commonElements.retainAll(sublist)
    }

    return commonElements
}
/**
 * This exercise aims to find the common elements in a nested list and return them as a list.
 * The input to this function is a list of lists, where each nested list represents a group of elements.
 * The function should find the elements that appear in all the nested lists and return them as a list.
 *
 * Example:
 * findCommonElements(listOf(listOf(1, 2, 3), listOf(4, 2, 5), listOf(2, 7, 8, 9))) should return [2].
 */
fun findCommonElements(lists: List<List<Int>>): List<Int> {
/**
 * This exercise aims to find the common elements in a nested list and return them as a list.
 * The input to this function is a list of lists, where each nested list represents a group of elements.
 * The function should find the elements that appear in all the nested lists and return them as a list.
 *
 * Example:
 * findCommonElements(listOf(listOf(1, 2, 3), listOf(4, 2, 5), listOf(2, 7, 8, 9))) should return [2].
 */
fun findCommonElements(lists: List<List<Int>>): List<Int> {

    var commonElements = lists[0].toMutableList() // Assume the first list as the initial reference

    for (sublist in lists.subList(1, lists.size)) { // Iterate through the remaining nested lists
        commonElements.retainAll(sublist)
    }

    return commonElements
}