3 lines in Ruby


  • 2

    First get a sorted list of events (time/change pairs). Then just go through that, updating the number of rooms, and returning the maximum seen.

    def min_meeting_rooms(intervals)
      rooms = 0
      intervals.flat_map { |i| [[i.start, 1], [i.end, -1]] }.sort
               .map { |_, change| rooms += change }.max || 0
    end

  • 0
    A

    yes, minimum # of rooms == maximum conflicting intervals


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.