/**
 * This exercise is about finding the intersection between two ranges, specified by their start and stop parameters.
 *
 * Write a function called 'intersection' that takes four parameters: start1, stop1, start2, and stop2.
 * The function should return a list of the numbers that are present in both ranges.
 * If there is no intersection, the function should return an empty list.
 *
 * Examples:
 * - intersection(1, 5, 4, 8) -> [4, 5]
 * - intersection(10, 15, 20, 25) -> []
 * - intersection(3, 7, 2, 8) -> [3, 4, 5, 6, 7]
 *
 * Your task is to implement the 'intersection' function below using Kotlin code.
 */
fun intersection(start1: Int, stop1: Int, start2: Int, stop2: Int): List<Int> {

    // Step 1: Check if there is any overlap between the two ranges
    if (stop1 < start2 || stop2 < start1) {
        return emptyList()
    }

    // Step 2: Find the intersection between the two ranges
    val intersection = mutableListOf<Int>()
    for (number in maxOf(start1, start2)..minOf(stop1, stop2)) {
        intersection.add(number)
    }

    return intersection
}
/**
 * This exercise is about finding the intersection between two ranges, specified by their start and stop parameters.
 *
 * Write a function called 'intersection' that takes four parameters: start1, stop1, start2, and stop2.
 * The function should return a list of the numbers that are present in both ranges.
 * If there is no intersection, the function should return an empty list.
 *
 * Examples:
 * - intersection(1, 5, 4, 8) -> [4, 5]
 * - intersection(10, 15, 20, 25) -> []
 * - intersection(3, 7, 2, 8) -> [3, 4, 5, 6, 7]
 *
 * Your task is to implement the 'intersection' function below using Kotlin code.
 */
fun intersection(start1: Int, stop1: Int, start2: Int, stop2: Int): List<Int> {
/**
 * This exercise is about finding the intersection between two ranges, specified by their start and stop parameters.
 *
 * Write a function called 'intersection' that takes four parameters: start1, stop1, start2, and stop2.
 * The function should return a list of the numbers that are present in both ranges.
 * If there is no intersection, the function should return an empty list.
 *
 * Examples:
 * - intersection(1, 5, 4, 8) -> [4, 5]
 * - intersection(10, 15, 20, 25) -> []
 * - intersection(3, 7, 2, 8) -> [3, 4, 5, 6, 7]
 *
 * Your task is to implement the 'intersection' function below using Kotlin code.
 */
fun intersection(start1: Int, stop1: Int, start2: Int, stop2: Int): List<Int> {

    // Step 1: Check if there is any overlap between the two ranges
    if (stop1 < start2 || stop2 < start1) {
        return emptyList()
    }

    // Step 2: Find the intersection between the two ranges
    val intersection = mutableListOf<Int>()
    for (number in maxOf(start1, start2)..minOf(stop1, stop2)) {
        intersection.add(number)
    }

    return intersection
}