/**
 * This function takes in two matrices and returns a list of common elements found in both matrices.
 *
 * @param matrix1 The first matrix.
 * @param matrix2 The second matrix.
 * @return A list of common elements found in both matrices.
 *
 * Example:
 * val matrix1 = listOf(listOf(1, 2), listOf(3, 4))
 * val matrix2 = listOf(listOf(3, 4), listOf(5, 6))
 * findCommonElements(matrix1, matrix2) // [3, 4]
 */
fun findCommonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Nested loop to iterate over each element in matrix1
    for (row1 in matrix1) {
        for (element1 in row1) {
            // Checking if element1 is present in matrix2
            for (row2 in matrix2) {
                for (element2 in row2) {
                    // Identity comparison to check if element1 and element2 are the same object
                    if (element1 === element2) {
                        commonElements.add(element1)
                    }
                }
            }
        }
    }

    return commonElements
}
/**
 * This function takes in two matrices and returns a list of common elements found in both matrices.
 *
 * @param matrix1 The first matrix.
 * @param matrix2 The second matrix.
 * @return A list of common elements found in both matrices.
 *
 * Example:
 * val matrix1 = listOf(listOf(1, 2), listOf(3, 4))
 * val matrix2 = listOf(listOf(3, 4), listOf(5, 6))
 * findCommonElements(matrix1, matrix2) // [3, 4]
 */
fun findCommonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {
/**
 * This function takes in two matrices and returns a list of common elements found in both matrices.
 *
 * @param matrix1 The first matrix.
 * @param matrix2 The second matrix.
 * @return A list of common elements found in both matrices.
 *
 * Example:
 * val matrix1 = listOf(listOf(1, 2), listOf(3, 4))
 * val matrix2 = listOf(listOf(3, 4), listOf(5, 6))
 * findCommonElements(matrix1, matrix2) // [3, 4]
 */
fun findCommonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Nested loop to iterate over each element in matrix1
    for (row1 in matrix1) {
        for (element1 in row1) {
            // Checking if element1 is present in matrix2
            for (row2 in matrix2) {
                for (element2 in row2) {
                    // Identity comparison to check if element1 and element2 are the same object
                    if (element1 === element2) {
                        commonElements.add(element1)
                    }
                }
            }
        }
    }

    return commonElements
}