Meeting Rooms II
Updated
Problem statement
You are given an array of meetings, intervals, where intervals[i] = [starti, endi]. Return the minimum number of rooms needed so that every meeting has a room for its whole time.
A meeting uses its room from starti up to, but not including, endi. So a room freed at time t can host a meeting that starts at t. The meetings can come in any order.
Function
minMeetingRooms(intervals: int[][]) → intExamples
Example 1
intervals = [[1,8],[2,4],[5,9]]return = 2The meeting [1,8] overlaps both others, so it needs its own room. [2,4] ends before [5,9] starts, so those two can share a second room.
Example 2
intervals = [[5,9],[2,5]]return = 1The first meeting to run, [2,5], ends at time 5, just as [5,9] starts. The room is free at that moment, so one room is enough. The input is not sorted.
Example 3
intervals = [[1,4],[2,5],[3,6],[7,8]]return = 3At time 3, the meetings [1,4], [2,5] and [3,6] are all running, so three rooms are needed. By time 7 they have all ended, so [7,8] can reuse a room.
Example 4
intervals = [[4,6]]return = 1One meeting needs one room.
Constraints
1 <= intervals.length <= 10^4intervals[i].length == 20 <= starti < endi <= 10^6
More Salesforce Onsite Interview questions
- Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
- Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
- 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
- Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
- Construct a Tree from Level-Order and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
- Maximize Monsters DefeatedONSITE INTERVIEW · Seen Sep 2026
- Flatten Nested Map Paths with a StackONSITE INTERVIEW · Seen Sep 2026
- LFU CacheONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
- Meeting Rooms IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Minimum Classrooms for CoursesGoogle · ONSITE INTERVIEWGoogle interview questions
- Merge K Sorted Interval ListsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Employee Free TimeIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Meeting Rooms IIByteDance · PHONE SCREENByteDance interview questions
- Minimum Meeting RoomsJP Morgan Chase · OAJP Morgan Chase interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions