Dsa
Intervals
Medium
Disjoint Interval Checker
Write a function that takes a list of intervals and returns whether there are any disjoint pairs of intervals in the list. Two intervals [a, b] and [c, d] are disjoint if b < c or d < a. The function should read from standard input the number of intervals followed by the intervals themselves and output 'Yes' if disjoint intervals exist, otherwise output 'No'.
Input Format:
- The first line contains an integer N (1 <= N <= 1000), the number of intervals.
- The next N lines each contain two integers representing the start and end of an interval.
Output Format:
- 'Yes' or 'No'.
Example Input:
3
1 3
5 7
2 4
Example Output:
Yes
Key concepts
intervalscheckingdisjoint
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now