Skip to the code
cf.
+25 XP

#587 Rooms Needed for Every Meeting

medium

An office booking system must give every meeting a room. Meeting i runs over [start, end], using its room from start up to end. A room freed at time t can host a meeting starting at time t.

Write roomsNeeded(meetings) that returns the smallest number of rooms that can host all the meetings.

Example 1

Input: meetings = [[0,40],[10,15],[20,25]]
Output: 2

The long meeting needs its own room; the two short ones share another.

Example 2

Input: meetings = [[7,10],[2,4]]
Output: 1

They don't overlap.

Constraints

  • 0 <= meetings.length <= 100000
  • 0 <= start < end <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).