Editor

Most Meetings in One Room

#93 · Greedy · Intermediate · 75 XP · about 14 min

meetings is a list of [start, end] times for meetings that all want the same room. Two meetings clash if their times overlap, but a meeting that ends at time t does not clash with one that starts at t.

Write max_meetings(meetings) that returns the largest number of meetings the room can host with no clashes.

Examples

max_meetings([[1, 4], [3, 5], [0, 6], [5, 7], [8, 9]])  # returns 3
max_meetings([[1, 10], [2, 3], [4, 5]])                 # returns 2
max_meetings([[1, 3], [3, 6], [6, 8]])                  # returns 3

In the second example the long meeting from 1 to 10 blocks both short ones, so it is better to drop it and keep the other two.

Constraints

  • 0 <= len(meetings) <= 10000
  • 0 <= start < end <= 10**9
  • The meetings come in no particular order

Ready?

Accept the challenge to start writing. A small timer counts the time this page is in view.

Output appears here.