Dsa
Intervals
Easy
Maximum Number of Non-overlapping Intervals
A team is working with a set of project intervals. Your goal is to select the maximum number of non-overlapping intervals that can be included in the schedule. Each interval is defined by a start and end time. You want to determine how many non-overlapping intervals can be selected.
The program should read from standard input, first with an integer n representing the number of intervals. The next n lines contain two integers for each interval (start, end). Your program should print the maximum number of non-overlapping intervals.
Input Format:
- An integer n (1 ≤ n ≤ 10000)
- n lines, each containing two integers (start, end) (0 ≤ start < end ≤ 10^9)
Output Format:
- An integer representing the maximum number of non-overlapping intervals.
Example:
Input:
5
1 3
2 4
3 5
4 6
7 8
Output:
4
Key concepts
intervalsselectiongreedy
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