/**
 * Given two lists of integers, find the common elements between the two lists and return them as a new list.
 *
 * @param numbers1 list of integers
 * @param numbers2 list of integers
 * @return List of common elements between numbers1 and numbers2
 *
 * Example:
 * intersection(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) => [4, 5]
 */
fun intersection(numbers1: List<Int>, numbers2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over each element in numbers1
    for (num1 in numbers1) {
        // Iterate over each element in numbers2
        for (num2 in numbers2) {
            // If num1 is equal to num2 and num1 is not already in commonElements
            if (num1 == num2 && num1 !in commonElements) {
                // Add num1 to commonElements
                commonElements.add(num1)
                break  // Break the inner loop to prevent duplicate elements in commonElements
            }
        }
    }

    return commonElements
}
/**
 * Given two lists of integers, find the common elements between the two lists and return them as a new list.
 *
 * @param numbers1 list of integers
 * @param numbers2 list of integers
 * @return List of common elements between numbers1 and numbers2
 *
 * Example:
 * intersection(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) => [4, 5]
 */
fun intersection(numbers1: List<Int>, numbers2: List<Int>): List<Int> {
/**
 * Given two lists of integers, find the common elements between the two lists and return them as a new list.
 *
 * @param numbers1 list of integers
 * @param numbers2 list of integers
 * @return List of common elements between numbers1 and numbers2
 *
 * Example:
 * intersection(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) => [4, 5]
 */
fun intersection(numbers1: List<Int>, numbers2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over each element in numbers1
    for (num1 in numbers1) {
        // Iterate over each element in numbers2
        for (num2 in numbers2) {
            // If num1 is equal to num2 and num1 is not already in commonElements
            if (num1 == num2 && num1 !in commonElements) {
                // Add num1 to commonElements
                commonElements.add(num1)
                break  // Break the inner loop to prevent duplicate elements in commonElements
            }
        }
    }

    return commonElements
}