/**
 * Given two lists, return a new list containing the common elements
 * between the two lists.
 *
 * Example:
 * If list1 = [1, 2, 3, 4, 5] and list2 = [4, 5, 6, 7, 8], the function
 * should return [4, 5].
 *
 * @param list1 The first input list.
 * @param list2 The second input list.
 * @return A new list containing the common elements between list1 and list2.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over each element in list1
    for (element in list1) {
        // Check if the element is also present in list2
        if (element in list2) {
            // Add the common element to the commonElements list
            commonElements.add(element)
        }
    }

    return commonElements
}
/**
 * Given two lists, return a new list containing the common elements
 * between the two lists.
 *
 * Example:
 * If list1 = [1, 2, 3, 4, 5] and list2 = [4, 5, 6, 7, 8], the function
 * should return [4, 5].
 *
 * @param list1 The first input list.
 * @param list2 The second input list.
 * @return A new list containing the common elements between list1 and list2.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, return a new list containing the common elements
 * between the two lists.
 *
 * Example:
 * If list1 = [1, 2, 3, 4, 5] and list2 = [4, 5, 6, 7, 8], the function
 * should return [4, 5].
 *
 * @param list1 The first input list.
 * @param list2 The second input list.
 * @return A new list containing the common elements between list1 and list2.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over each element in list1
    for (element in list1) {
        // Check if the element is also present in list2
        if (element in list2) {
            // Add the common element to the commonElements list
            commonElements.add(element)
        }
    }

    return commonElements
}