Dsa
Intervals
Easy
Interval Overlaps
You are given a list of intervals where each interval is represented as a pair of integers [start, end]. Write a program that determines if any of the intervals overlap with at least one other interval. An interval [a, b] overlaps with another interval [c, d] if and only if a <= d and c <= b. Print 'Yes' if any overlaps exist, otherwise print 'No'.
Input format:
- The first line contains an integer n, the number of intervals.
- The next n lines each contain two integers, start and end, separated by a space.
Output format:
- Print 'Yes' or 'No'.
Example:
Input:
3
1 3
2 4
5 7
Output:
Yes
Key concepts
intervalsmergingsorting
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