N Meetings in One Room

easy

There is one meeting room. You are given a list of meetings, where each meeting is [start, end]. Only one meeting can occupy the room at a time, and a meeting can start only strictly after the previous one ends (a start time equal to another's end time counts as a clash).

Return the maximum number of meetings the room can host.

Hints

You want the most non-overlapping meetings — which one should you always pick first?
Sort the meetings by their end time.
Greedily take each meeting that starts strictly after the last one you kept.

Common doubts

The meeting that ends earliest frees the room soonest, leaving the most room for future meetings. Sorting by start can pick a long meeting that blocks several short ones.
The problem treats a meeting starting exactly when another ends as a clash, so only a strictly-later start is compatible.
Yes — an exchange argument shows replacing any optimal schedule's first meeting with the earliest finisher never loses a later meeting, so the greedy matches the optimum.

Interview follow-ups

Then greedy fails; it becomes weighted interval scheduling, solved by sorting by end and DP with binary search for the last compatible meeting.
Sort by start and use a min-heap of end times; a meeting reuses a room whose meeting has ended, otherwise opens a new one (bounded by k).

Fun facts

  • Activity selection is the canonical greedy proof in algorithms courses — the earliest-finish rule is provably optimal via a clean exchange argument.
  • The same 'earliest finish' idea schedules jobs on a single machine to maximize throughput.

Asked at

AmazonGoogleMicrosoft
Frequently Sometimes Occasionally
Example 1
Input: meetings = [[1,2],[3,4],[0,6],[5,7],[8,9],[5,9]]
Output: 4
Choose meetings [1,2], [3,4], [5,7], [8,9] — four non-overlapping meetings.
Example 2
Input: meetings = [[10,20],[12,25],[20,30]]
Output: 1
All three overlap pairwise (and [10,20] touches [20,30] at 20), so only one fits.
Constraints

- 1 <= meetings.length <= 10^5 - 0 <= start < end <= 10^9

Solve this problem →