/**
 * Given a list of ranges with negative values, find the intersection of all the ranges.
 */
fun findIntersection(rangeList: List<Pair<Int, Int>>): List<Pair<Int, Int>> {

    // Sort the range list based on the starting point in ascending order
    val sortedRangeList = rangeList.sortedBy { it.first }

    // Initialize the start and end variables with the starting range
    var (start, end) = sortedRangeList[0]

    // Initialize an empty result list to store the intersections
    val intersections = mutableListOf<Pair<Int, Int>>()

    // Iterate over the remaining ranges
    for (i in 1 until sortedRangeList.size) {
        val (currStart, currEnd) = sortedRangeList[i]

        // Check if the current range intersects with the previous range
        if (currStart <= end) {
            // Update the end variable to the minimum of current end and previous end
            end = minOf(end, currEnd)
        } else {
            // If current range does not intersect, add the current intersection to the result list
            intersections.add(Pair(start, end))

            // Update the start and end variables to the current range
            start = currStart
            end = currEnd
        }
    }

    // Add the last intersection to the result list
    intersections.add(Pair(start, end))

    return intersections
}
/**
 * Given a list of ranges with negative values, find the intersection of all the ranges.
 */
fun findIntersection(rangeList: List<Pair<Int, Int>>): List<Pair<Int, Int>> {
/**
 * Given a list of ranges with negative values, find the intersection of all the ranges.
 */
fun findIntersection(rangeList: List<Pair<Int, Int>>): List<Pair<Int, Int>> {

    // Sort the range list based on the starting point in ascending order
    val sortedRangeList = rangeList.sortedBy { it.first }

    // Initialize the start and end variables with the starting range
    var (start, end) = sortedRangeList[0]

    // Initialize an empty result list to store the intersections
    val intersections = mutableListOf<Pair<Int, Int>>()

    // Iterate over the remaining ranges
    for (i in 1 until sortedRangeList.size) {
        val (currStart, currEnd) = sortedRangeList[i]

        // Check if the current range intersects with the previous range
        if (currStart <= end) {
            // Update the end variable to the minimum of current end and previous end
            end = minOf(end, currEnd)
        } else {
            // If current range does not intersect, add the current intersection to the result list
            intersections.add(Pair(start, end))

            // Update the start and end variables to the current range
            start = currStart
            end = currEnd
        }
    }

    // Add the last intersection to the result list
    intersections.add(Pair(start, end))

    return intersections
}