/**
 * Given two arrays, find the common elements between them.
 *
 * @param list1 The first array consisting of integers (M elements)
 * @param list2 The second array consisting of integers (N elements)
 * @return A list of common elements between list1 and list2
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8))
 * Output: [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Use Boolean operations to find common elements
    for (num1 in list1) {
        if (num1 in list2 && num1 !in commonElements) {
            commonElements.add(num1)
        }
    }

    return commonElements
}
/**
 * Given two arrays, find the common elements between them.
 *
 * @param list1 The first array consisting of integers (M elements)
 * @param list2 The second array consisting of integers (N elements)
 * @return A list of common elements between list1 and list2
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8))
 * Output: [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two arrays, find the common elements between them.
 *
 * @param list1 The first array consisting of integers (M elements)
 * @param list2 The second array consisting of integers (N elements)
 * @return A list of common elements between list1 and list2
 *
 * Example:
 * findCommonElements(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8))
 * Output: [4, 5]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Use Boolean operations to find common elements
    for (num1 in list1) {
        if (num1 in list2 && num1 !in commonElements) {
            commonElements.add(num1)
        }
    }

    return commonElements
}