← Practice problem bank

Jan 19, 2026

The Efficient Meeting Schedule

Daily Challenge Archive · Open

easysorting

100 pts · 10000 ms · 128 MB · Practice only

Problem

Imagine you are a busy event organizer tasked with attending as many conference sessions as possible in a single day. Each session has a designated start and end time, and your goal is to attend as many non-overlapping sessions as possible. This involves selecting sessions in such a way that no two sessions overlap, ensuring you make the most of your available time. To solve this problem, follow these steps: 1. List all the sessions with their respective start and end times. 2. Sort the sessions based on their end times. 3. Select the first session that ends the earliest and attend it. 4. For each subsequent session, check if its start time is after the end time of the last attended session. If yes, attend it; if not, skip to the next one. 5. Repeat this process until you have gone through all the sessions. For example, if you have sessions [(1, 4), (3, 5), (0, 6), (5, 7), (8, 9)], you would attend sessions (1, 4), (5, 7), and (8, 9), maximizing your attendance to three sessions. Edge cases to consider include sessions that start and end at the same time or multiple sessions with the same end time.

Hints
Consider using a greedy algorithm approach by always selecting the session that ends the earliest and doesn't overlap with previously selected sessions. Sorting the sessions by their end time first can significantly simplify the selection process. Remember to think about sessions that might have the same start or end times and how they can fit into your schedule.

Input format

The first line contains an integer n, the number of meetings. The next n lines each contain two integers, start and end, representing the start and end times of the meetings.

Output format

Output a single integer, the maximum number of non-overlapping meetings that can be attended.

Constraints

1 <= n <= 10^4; 0 <= start < end <= 10^9;

Sample input

3
1 3
2 4
3 5

Sample output

2

Sign in to submit solutions

Run your code against all test cases and get instant feedback.

Sign in