/**
 * This function takes in two matrices, matrix1 and matrix2, and finds the common elements between them.
 *
 * @param matrix1 A nested list representing a matrix.
 * @param matrix2 A nested list representing a matrix.
 * @return A list containing the common elements between matrix1 and matrix2.
 */
fun findCommonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate through each sublist in matrix1
    for (sublist in matrix1) {
        // Iterate through each element in sublist
        for (element in sublist) {
            // Check if the element is present in every sublist of matrix2
            if (matrix2.all { sub -> element in sub }) {
                commonElements.add(element)
            }
        }
    }

    return commonElements
}
/**
 * This function takes in two matrices, matrix1 and matrix2, and finds the common elements between them.
 *
 * @param matrix1 A nested list representing a matrix.
 * @param matrix2 A nested list representing a matrix.
 * @return A list containing the common elements between matrix1 and matrix2.
 */
fun findCommonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {
/**
 * This function takes in two matrices, matrix1 and matrix2, and finds the common elements between them.
 *
 * @param matrix1 A nested list representing a matrix.
 * @param matrix2 A nested list representing a matrix.
 * @return A list containing the common elements between matrix1 and matrix2.
 */
fun findCommonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate through each sublist in matrix1
    for (sublist in matrix1) {
        // Iterate through each element in sublist
        for (element in sublist) {
            // Check if the element is present in every sublist of matrix2
            if (matrix2.all { sub -> element in sub }) {
                commonElements.add(element)
            }
        }
    }

    return commonElements
}