Segment Overlap
Two closed segments [A, B] and [C, D] lie on a number line. Print the length of their overlap (0 if they do not intersect).
Input: one line with four integers A B C D (A ≤ B, C ≤ D).
Output: the overlap length: max(0, min(B, D) − max(A, C)).
Constraints:
- −109 ≤ A ≤ B ≤ 109
- −109 ≤ C ≤ D ≤ 109
Sample Tests
Input 1
1 5 3 8
Output 1
2
Input 2
1 2 5 6
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.