/**
 * Given two lists, find the intersection of the two lists.
 *
 * @param list1 the first list
 * @param list2 the second list
 * @return List containing the intersection elements of list1 and list2
 */
fun intersectLists(list1: List<Int>, list2: List<Int>): List<Int> {

    // Sort the lists
    val sortedList1 = list1.sorted()
    val sortedList2 = list2.sorted()

    // Initialize variables
    var i = 0
    var j = 0
    val intersection = mutableListOf<Int>()

    // Find the intersection
    while (i < sortedList1.size && j < sortedList2.size) {
        when {
            sortedList1[i] == sortedList2[j] -> {
                intersection.add(sortedList1[i])
                i++
                j++
            }
            sortedList1[i] < sortedList2[j] -> i++
            else -> j++
        }
    }

    return intersection
}
/**
 * Given two lists, find the intersection of the two lists.
 *
 * @param list1 the first list
 * @param list2 the second list
 * @return List containing the intersection elements of list1 and list2
 */
fun intersectLists(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists, find the intersection of the two lists.
 *
 * @param list1 the first list
 * @param list2 the second list
 * @return List containing the intersection elements of list1 and list2
 */
fun intersectLists(list1: List<Int>, list2: List<Int>): List<Int> {

    // Sort the lists
    val sortedList1 = list1.sorted()
    val sortedList2 = list2.sorted()

    // Initialize variables
    var i = 0
    var j = 0
    val intersection = mutableListOf<Int>()

    // Find the intersection
    while (i < sortedList1.size && j < sortedList2.size) {
        when {
            sortedList1[i] == sortedList2[j] -> {
                intersection.add(sortedList1[i])
                i++
                j++
            }
            sortedList1[i] < sortedList2[j] -> i++
            else -> j++
        }
    }

    return intersection
}