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, 2 to 6 and 4 to 8 all run, so you need at least 3 rooms. Three are enough: the meeting from 7 to 9 takes the room freed at 5.
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 #1

Test #2

Test #3

Arguments

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

Expected Output

3