Skip to content
Search lessons, topics, tests…
Esc

    ↑ ↓ moveEnter openEsc close

    Coding problem

    How many meeting rooms are needed

    MediumAbout 25 minFull AccessLearn it: Interval Problems in C#: Merge, Insert, Greedy Scheduling, Meeting Rooms and Sweep Lines

    The task

    An office booking tool must know how many rooms a day's meetings need.

    Complete RoomsNeeded(int[][] meetings). Each meeting is [start, end] with start < end, and it uses a room from start up to, but not including, end: a meeting that ends at t frees its room for one that starts at t. Return the fewest rooms that hold all the meetings. Meetings can come in any order.

    Signature

    public static int RoomsNeeded(int[][] meetings)

    Examples

    • [[1, 5], [5, 9]] → 1. The second meeting starts just as the first one ends.
    • [[8, 10], [9, 13], [12, 14]] → 2. 8–10 and 9–13 overlap; the first room is free again at 10, in time for the meeting at 12.

    Limits: Up to 200,000 meetings.

    The tests check: no meetings, one meeting, back-to-back meetings, overlapping and identical meetings, meetings out of order, a chain of overlaps, nested meetings, and 200,000 meetings in time.

    Hints

      Your code

      C#Solution.csLoading the editor…

      Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;

      public static class Solution
      {
          // Each meeting is [start, end) with start < end; returns the fewest rooms that hold them all.
          public static int RoomsNeeded(int[][] meetings)
          {
              throw new NotImplementedException();
          }
      }

      This problem comes with TechInterviewNotes Full Access

      Unlock all paid content on TechInterviewNotes.