Menu
CoddyTech

Meeting Rooms II

You get a list of meetings as two arrays: meeting i runs from starts[i] to ends[i]. A room holds one meeting at a time, and a meeting may start in a room at the exact moment another meeting there ends.

Write a function named minMeetingRooms that returns the smallest number of rooms that can hold all the meetings.

Function

minMeetingRooms(starts: integer-array, ends: integer-array) → integer
startsinteger-array
the start time of each meeting
endsinteger-array
the end time of each meeting, at the same index as its start
Returnsinteger
the fewest rooms that can hold every meeting

Constraints

  • 1 ≤ starts.length == ends.length ≤ 5000
  • 0 ≤ starts[i] < ends[i] ≤ 106
  • The meetings are not sorted. Two meetings may be identical.

Examples

Input
starts = [4, 1, 7, 2]ends = [8, 5, 9, 6]
Output
3
Explanation
At time 4 the meetings from 1 to 5, from 2 to 6 and from 4 to 8 are all running, so you need at least 3 rooms. Three are enough: the meeting from 7 to 9 takes the room that frees up at 5.

lock icon+17 hidden tests on Submit

challenge icon

Follow-up

Can you also say which room each meeting goes to, using no more rooms than the answer?

Reset code
def minMeetingRooms(starts, ends):
    # Write code here
Test cases

Case 1

Case 2

Case 3

Input

starts = [4, 1, 7, 2]
ends = [8, 5, 9, 6]

Expected

3