/**
 * Returns a tuple with the elements that are common to both input tuples.
 *
 * Assume that both tuples contain only unique elements.
 *
 * @param tuple1 The first input tuple.
 * @param tuple2 The second input tuple.
 * @return A tuple with the common elements.
 *
 * Example:
 * findIntersection(listOf(1, 2, 3), listOf(2, 3, 4)) // Output: [2, 3]
 */
fun findIntersection(tuple1: List<Int>, tuple2: List<Int>): List<Int> {

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

    while (i < tuple1.size && j < tuple2.size) {
        when {
            tuple1[i] == tuple2[j] -> {
                intersection.add(tuple1[i])
                i++
                j++
            }
            tuple1[i] < tuple2[j] -> i++
            else -> j++
        }
    }

    return intersection
}

// Create two tuples
val tuple1 = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val tuple2 = listOf(2, 4, 6)
/**
 * Returns a tuple with the elements that are common to both input tuples.
 *
 * Assume that both tuples contain only unique elements.
 *
 * @param tuple1 The first input tuple.
 * @param tuple2 The second input tuple.
 * @return A tuple with the common elements.
 *
 * Example:
 * findIntersection(listOf(1, 2, 3), listOf(2, 3, 4)) // Output: [2, 3]
 */
fun findIntersection(tuple1: List<Int>, tuple2: List<Int>): List<Int> {
/**
 * Returns a tuple with the elements that are common to both input tuples.
 *
 * Assume that both tuples contain only unique elements.
 *
 * @param tuple1 The first input tuple.
 * @param tuple2 The second input tuple.
 * @return A tuple with the common elements.
 *
 * Example:
 * findIntersection(listOf(1, 2, 3), listOf(2, 3, 4)) // Output: [2, 3]
 */
fun findIntersection(tuple1: List<Int>, tuple2: List<Int>): List<Int> {

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

    while (i < tuple1.size && j < tuple2.size) {
        when {
            tuple1[i] == tuple2[j] -> {
                intersection.add(tuple1[i])
                i++
                j++
            }
            tuple1[i] < tuple2[j] -> i++
            else -> j++
        }
    }

    return intersection
}

// Create two tuples
val tuple1 = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val tuple2 = listOf(2, 4, 6)