/**
 * Determine the intersection of two given lists using the range function.
 * Explain the advantages of using the range function in this context.
 *
 * @param list1 the first list
 * @param list2 the second list
 * @return A list containing the common elements between list1 and list2.
 */
fun intersectionOfRangeWithListsAdvantages(list1: List<Int>, list2: List<Int>): List<Int> {

    val intersection = mutableListOf<Int>()

    // Check if each element in list1 is also present in list2
    for (element in list1) {
        for (i in list2.indices) {
            if (element == list2[i]) {
                intersection.add(element)
                break
            }
        }
    }

    return intersection
}
/**
 * Determine the intersection of two given lists using the range function.
 * Explain the advantages of using the range function in this context.
 *
 * @param list1 the first list
 * @param list2 the second list
 * @return A list containing the common elements between list1 and list2.
 */
fun intersectionOfRangeWithListsAdvantages(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Determine the intersection of two given lists using the range function.
 * Explain the advantages of using the range function in this context.
 *
 * @param list1 the first list
 * @param list2 the second list
 * @return A list containing the common elements between list1 and list2.
 */
fun intersectionOfRangeWithListsAdvantages(list1: List<Int>, list2: List<Int>): List<Int> {

    val intersection = mutableListOf<Int>()

    // Check if each element in list1 is also present in list2
    for (element in list1) {
        for (i in list2.indices) {
            if (element == list2[i]) {
                intersection.add(element)
                break
            }
        }
    }

    return intersection
}