Minimum Classrooms for Courses
Updated
Problem statement
You are given an array courses, where courses[i] = [starti, endi] is the scheduled time of the i-th course.
Each classroom can host at most one course at a time. A classroom becomes available immediately when a course ends, so a course ending at time t does not overlap a course starting at time t.
Return the minimum number of classrooms required to hold every course at its scheduled time.
Function
minimumClassrooms(courses: int[][]) → intExamples
Example 1
courses = [[0,30],[5,10],[15,20]]return = 2The courses [0,30] and [5,10] overlap, so at least two classrooms are necessary. Two are also sufficient.
Example 2
courses = [[1,5],[5,8],[8,9]]return = 1Every course starts when or after the previous course ends, so one classroom can be reused.
Example 3
courses = [[4,10],[4,10],[4,10]]return = 3All three courses run at the same time, so each needs a separate classroom.
Constraints
1 <= courses.length <= 100000.courses[i].length == 2.0 <= starti < endi <= 1000000000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
- 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
- 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