/**
 * Given two lists, find the common elements between them.
 *
 * Example:
 * ----------
 * Input:
 *     list1 = [5, 2, 6, 1, 9]
 *     list2 = [7, 2, 3, 4, 1]
 * Output:
 *     [2, 1]
 *
 * Input:
 *     list1 = [10, 20, 30, 40]
 *     list2 = [10, 50, 30, 70, 40]
 * Output:
 *     [10, 30, 40]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over elements in list1
    for (element in list1) {
        if (element in list2) {  // Check if the element is present in list2
            commonElements.add(element)
        }
    }

    return commonElements
}
/**
 * Given two lists, find the common elements between them.
 *
 * Example:
 * ----------
 * Input:
 *     list1 = [5, 2, 6, 1, 9]
 *     list2 = [7, 2, 3, 4, 1]
 * Output:
 *     [2, 1]
 *
 * Input:
 *     list1 = [10, 20, 30, 40]
 *     list2 = [10, 50, 30, 70, 40]
 * Output:
 *     [10, 30, 40]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, find the common elements between them.
 *
 * Example:
 * ----------
 * Input:
 *     list1 = [5, 2, 6, 1, 9]
 *     list2 = [7, 2, 3, 4, 1]
 * Output:
 *     [2, 1]
 *
 * Input:
 *     list1 = [10, 20, 30, 40]
 *     list2 = [10, 50, 30, 70, 40]
 * Output:
 *     [10, 30, 40]
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over elements in list1
    for (element in list1) {
        if (element in list2) {  // Check if the element is present in list2
            commonElements.add(element)
        }
    }

    return commonElements
}