#C7851. Interval Insertion Without Overlap
Interval Insertion Without Overlap
Interval Insertion Without Overlap
You are given a list of non-overlapping intervals and a target interval. Your task is to determine whether the target interval can be added to the list without overlapping any of the existing intervals.
An interval is represented by a pair of numbers (start, end). Two intervals \([a, b]\) and \([c, d]\) are said to overlap if \(a < d\) and \(b > c\). The target interval can be inserted if it does not overlap with any of the intervals in the list.
Note: Consider the intervals to be in a continuous number line and the input values may be integers or floats.
inputFormat
The input is given via standard input (stdin) in the following format:
- An integer
n
representing the number of existing intervals. n
lines follow, each line contains two numbers (start and end) separated by space representing an interval.- One line with two numbers separated by space representing the target interval.
Example:
3 1 3 5 8 10 15 3 5
outputFormat
The output is a single line to standard output (stdout) containing either True
or False
depending on whether the target interval can be added without overlapping any existing intervals.
Example:
True## sample
3
1 3
5 8
10 15
3 5
True