/**
 * Given two matrices, find the common elements using nested loops and slicing.
 *
 * @param matrix1 a list of lists representing the first matrix
 * @param matrix2 a list of lists representing the second matrix
 * @return a list containing the common elements between the two matrices
 */
fun commonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {

    val common = mutableListOf<Int>()

    for (row in matrix1) {
        for (element in row) {
            for (row2 in matrix2) {
                if (element in row2) {
                    common.add(element)
                    break
                }
            }
        }
    }

    return common
}
/**
 * Given two matrices, find the common elements using nested loops and slicing.
 *
 * @param matrix1 a list of lists representing the first matrix
 * @param matrix2 a list of lists representing the second matrix
 * @return a list containing the common elements between the two matrices
 */
fun commonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {
/**
 * Given two matrices, find the common elements using nested loops and slicing.
 *
 * @param matrix1 a list of lists representing the first matrix
 * @param matrix2 a list of lists representing the second matrix
 * @return a list containing the common elements between the two matrices
 */
fun commonElements(matrix1: List<List<Int>>, matrix2: List<List<Int>>): List<Int> {

    val common = mutableListOf<Int>()

    for (row in matrix1) {
        for (element in row) {
            for (row2 in matrix2) {
                if (element in row2) {
                    common.add(element)
                    break
                }
            }
        }
    }

    return common
}