/**
 * Given a list of arrays, this function returns a list of common elements that appear in all arrays.
 *
 * @param arrays A list of arrays, where each array consists of unique integer elements.
 * @return A list of common elements present in all arrays.
 *
 * Example:
 * findCommonElements(listOf(listOf(1, 2, 3), listOf(2, 3, 4), listOf(2, 5, 6))) // [2]
 * findCommonElements(listOf(listOf(1, 2, 3, 4), listOf(2, 6, 8), listOf(4, 5, 2))) // [2]
 * findCommonElements(listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))) // []
 */
fun findCommonElements(arrays: List<List<Int>>): List<Int> {

    val commonElements = mutableListOf<Int>()

    if (arrays.size < 2) {
        return commonElements
    }

    val firstArray = arrays[0]
    for (element in firstArray) {
        var isCommon = true
        for (array in arrays.subList(1, arrays.size)) {
            if (element !in array) {
                isCommon = false
                break
            }
        }
        if (isCommon) {
            commonElements.add(element)
        }
    }

    return commonElements
}
/**
 * Given a list of arrays, this function returns a list of common elements that appear in all arrays.
 *
 * @param arrays A list of arrays, where each array consists of unique integer elements.
 * @return A list of common elements present in all arrays.
 *
 * Example:
 * findCommonElements(listOf(listOf(1, 2, 3), listOf(2, 3, 4), listOf(2, 5, 6))) // [2]
 * findCommonElements(listOf(listOf(1, 2, 3, 4), listOf(2, 6, 8), listOf(4, 5, 2))) // [2]
 * findCommonElements(listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))) // []
 */
fun findCommonElements(arrays: List<List<Int>>): List<Int> {
/**
 * Given a list of arrays, this function returns a list of common elements that appear in all arrays.
 *
 * @param arrays A list of arrays, where each array consists of unique integer elements.
 * @return A list of common elements present in all arrays.
 *
 * Example:
 * findCommonElements(listOf(listOf(1, 2, 3), listOf(2, 3, 4), listOf(2, 5, 6))) // [2]
 * findCommonElements(listOf(listOf(1, 2, 3, 4), listOf(2, 6, 8), listOf(4, 5, 2))) // [2]
 * findCommonElements(listOf(listOf(1, 2, 3), listOf(4, 5, 6), listOf(7, 8, 9))) // []
 */
fun findCommonElements(arrays: List<List<Int>>): List<Int> {

    val commonElements = mutableListOf<Int>()

    if (arrays.size < 2) {
        return commonElements
    }

    val firstArray = arrays[0]
    for (element in firstArray) {
        var isCommon = true
        for (array in arrays.subList(1, arrays.size)) {
            if (element !in array) {
                isCommon = false
                break
            }
        }
        if (isCommon) {
            commonElements.add(element)
        }
    }

    return commonElements
}