/**
 * Given two matrices, find and return the common elements that appear in both matrices.
 *
 * @param matrix1 A 2D list representing the first matrix.
 * @param matrix2 A 2D list representing the second matrix.
 * @return A list containing the common elements found in both matrices.
 */
fun findCommonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {

    val commonElements = mutableListOf<Int>()

    for (row1 in matrix1) {
        for (element in row1) {
            for (row2 in matrix2) {
                if (element in row2 && element !in commonElements) {
                    commonElements.add(element)
                }
            }
        }
    }

    return commonElements
}
/**
 * Given two matrices, find and return the common elements that appear in both matrices.
 *
 * @param matrix1 A 2D list representing the first matrix.
 * @param matrix2 A 2D list representing the second matrix.
 * @return A list containing the common elements found in both matrices.
 */
fun findCommonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {
/**
 * Given two matrices, find and return the common elements that appear in both matrices.
 *
 * @param matrix1 A 2D list representing the first matrix.
 * @param matrix2 A 2D list representing the second matrix.
 * @return A list containing the common elements found in both matrices.
 */
fun findCommonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {

    val commonElements = mutableListOf<Int>()

    for (row1 in matrix1) {
        for (element in row1) {
            for (row2 in matrix2) {
                if (element in row2 && element !in commonElements) {
                    commonElements.add(element)
                }
            }
        }
    }

    return commonElements
}