/**
 * Given two lists of integers, find and return a sorted list containing the common elements between the two lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A sorted list containing the common elements.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over the unique numbers in list1
    for (num in list1.toSet()) {
        // Check if the number is also present in list2 using range
        if (num in (list2.minOrNull()!!..list2.maxOrNull()!!)) {
            commonElements.add(num)
        }
    }

    return commonElements.sorted()
}
/**
 * Given two lists of integers, find and return a sorted list containing the common elements between the two lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A sorted list containing the common elements.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Given two lists of integers, find and return a sorted list containing the common elements between the two lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A sorted list containing the common elements.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over the unique numbers in list1
    for (num in list1.toSet()) {
        // Check if the number is also present in list2 using range
        if (num in (list2.minOrNull()!!..list2.maxOrNull()!!)) {
            commonElements.add(num)
        }
    }

    return commonElements.sorted()
}