/**
 * Given two intervals on the number line, represented by their start and end points,
 * find the intersection between them.
 *
 * @param start1 The start point of the first interval.
 * @param end1 The end point of the first interval.
 * @param start2 The start point of the second interval.
 * @param end2 The end point of the second interval.
 * @return The intersection between the two intervals, i.e., the length of the overlapping segment.
 *
 * Example:
 * numberLineIntersection(2, 8, 5, 12) // 3
 * numberLineIntersection(1, 10, -5, 3) // 4
 */
fun numberLineIntersection(start1: Int, end1: Int, start2: Int, end2: Int): Int {

    // Find the minimum end point and the maximum start point to determine the intersection
    val intersectionStart = maxOf(start1, start2)
    val intersectionEnd = minOf(end1, end2)

    // Calculate the length of the intersection
    val intersectionLength = intersectionEnd - intersectionStart

    return intersectionLength
}
/**
 * Given two intervals on the number line, represented by their start and end points,
 * find the intersection between them.
 *
 * @param start1 The start point of the first interval.
 * @param end1 The end point of the first interval.
 * @param start2 The start point of the second interval.
 * @param end2 The end point of the second interval.
 * @return The intersection between the two intervals, i.e., the length of the overlapping segment.
 *
 * Example:
 * numberLineIntersection(2, 8, 5, 12) // 3
 * numberLineIntersection(1, 10, -5, 3) // 4
 */
fun numberLineIntersection(start1: Int, end1: Int, start2: Int, end2: Int): Int {
/**
 * Given two intervals on the number line, represented by their start and end points,
 * find the intersection between them.
 *
 * @param start1 The start point of the first interval.
 * @param end1 The end point of the first interval.
 * @param start2 The start point of the second interval.
 * @param end2 The end point of the second interval.
 * @return The intersection between the two intervals, i.e., the length of the overlapping segment.
 *
 * Example:
 * numberLineIntersection(2, 8, 5, 12) // 3
 * numberLineIntersection(1, 10, -5, 3) // 4
 */
fun numberLineIntersection(start1: Int, end1: Int, start2: Int, end2: Int): Int {

    // Find the minimum end point and the maximum start point to determine the intersection
    val intersectionStart = maxOf(start1, start2)
    val intersectionEnd = minOf(end1, end2)

    // Calculate the length of the intersection
    val intersectionLength = intersectionEnd - intersectionStart

    return intersectionLength
}