Consolidated On-Call Rotations
Updated
Problem statement
You are given a list of on-call rotations. Each rotation has a person's name, a start time and an end time. The person is on call from the start time up to, but not including, the end time. That is the half-open interval [start, end).
Build the combined on-call schedule. Split the time when someone is on call into segments. Inside one segment, the group of people on call never changes. Make each segment as long as possible. Leave out any gap when no one is on call.
Each input rotation is a string in the form "name,start,end". Return each segment as a string in the form "start,end,name1,name2,...". Inside a segment, list the names in lexicographic order, which means comparing them as strings.
Function
getOnCallSchedule(rotations: String[]) → String[] Complete getOnCallSchedule.
String rotations[n]: the on-call rotations
Returns String[]: the schedule segments, sorted by start time.
Examples
Example 1
rotations = ["A,10,50","B,20,60","C,30,40","D,30,40"]return = ["10,20,A","20,30,A,B","30,40,A,B,C,D","40,50,A,B","50,60,B"]The same example as input and output tables:
Input rotations
| name | start | end |
|---|---|---|
A | 10 | 50 |
B | 20 | 60 |
C | 30 | 40 |
D | 30 | 40 |
Consolidated schedule
| start | end | names |
|---|---|---|
10 | 20 | A |
20 | 30 | A, B |
30 | 40 | A, B, C, D |
40 | 50 | A, B |
50 | 60 | B |
The active set changes at times 10, 20, 30, 40, 50, and 60.
Example 2
rotations = ["Nina,1,3","Omar,5,7"]return = ["1,3,Nina","5,7,Omar"]Nina is on call until 3 and Omar starts at 5. No one is on call in that gap, so it is left out of the schedule.
Constraints
- 0 <= rotations.length <= 10^5
- 0 <= start < end <= 10^9
- Names contain no commas.
More Google Online Assessment questions
- Book Reading EveningsOA · Seen Nov 2026
- Count Score CategoriesOA · Seen Nov 2026
- Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Shortest Path in a Binary MatrixOA · Seen Nov 2026
- Robot Assembly Line ConflictsOA · Seen Oct 2026
- Assign LockerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Biggest Number From DigitsOA · Seen Oct 2026
- Consolidate On-Call RotationsOA · PHONE SCREEN · Seen Oct 2026
- Decreasing SubsequencesOA · Seen Sep 2026
- Minimize Absolute Difference of Server LoadsOA · Seen Sep 2026
Similar questions at other companies
- Minimum Meeting RoomsJP Morgan Chase · OAJP Morgan Chase interview questions
- Process SchedulerGoldman Sachs · OAGoldman Sachs interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Meeting Rooms IIByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
- Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
- Minimum Meeting Rooms with AssignmentsUber · PHONE SCREEN · ONSITE INTERVIEWUber interview questions
- Meeting Rooms IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions