/**
 * This function takes two lists as input and returns a list containing their common elements.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    var index1 = 0
    var index2 = 0

    while (index1 < list1.size && index2 < list2.size) {
        when {
            list1[index1] == list2[index2] -> {
                commonElements.add(list1[index1])
                index1++
                index2++
            }
            list1[index1] < list2[index2] -> index1++
            else -> index2++
        }
    }

    return commonElements
}
/**
 * This function takes two lists as input and returns a list containing their common elements.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This function takes two lists as input and returns a list containing their common elements.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    var index1 = 0
    var index2 = 0

    while (index1 < list1.size && index2 < list2.size) {
        when {
            list1[index1] == list2[index2] -> {
                commonElements.add(list1[index1])
                index1++
                index2++
            }
            list1[index1] < list2[index2] -> index1++
            else -> index2++
        }
    }

    return commonElements
}