Problem · Intervals

Consolidated On-Call Rotations

Learn this problem
MediumGoogleOA
See Google hiring insights

Problem statement

You are given on-call rotations. Each rotation contains a person name, a start time, and an end time, and represents the half-open interval [start, end).

Produce the consolidated on-call schedule. Each output segment must be a maximal contiguous time range during which the set of people on call does not change. Omit gaps where no one is on call.

Input rotations are provided as strings formatted "name,start,end". Return strings formatted "start,end,name1,name2,...", with names in lexicographic order inside each segment.

Function

getOnCallSchedule(rotations: String[]) → String[]

Complete getOnCallSchedule.

  • String rotations[n]: on-call intervals

Returns

String[]: consolidated 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 original interview report presents this example as input and output tables.

Input rotations

namestartend
A1050
B2060
C3040
D3040

Consolidated schedule

startendnames
1020A
2030A, B
3040A, B, C, D
4050A, B
5060B

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"]

The gap from 3 to 5 has no on-call person and is omitted.

Constraints

  • 0 <= rotations.length <= 10^5
  • 0 <= start < end <= 10^9
  • Names contain no commas.

More Google problems

drafts saved locally
public String[] getOnCallSchedule(String[] rotations) {
  // write your code here
}
rotations["A,10,50","B,20,60","C,30,40","D,30,40"]
expected["10", "20", "A", "20", "30", "A", "B", "30", "40", "A", "B", "C", "D", "40", "50", "A", "B", "50", "60", "B"]
checking account