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

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

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

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

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

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

    return commonElements
}