FastPrepFastPrep
Problem Brief

Consolidate On-Call Rotations

FULLTIMEOA
See Google online assessment and hiring insights

You are given a list of on-call rotations. Each rotation has a name, start time, and end time, representing a half-open interval [start, end) during which that person is on call.

Produce the consolidated on-call timeline as maximal contiguous segments. In each output segment, the set of on-call people must remain constant throughout the entire interval. Sort segments by start time and omit gaps where nobody is on call.

Represent each input row as [name, start, end]. Return each output row as [start, end, names], where names is a comma-separated list of on-call names in lexicographic order.

1Example 1

Input
rotations = [["A", "10", "50"], ["B", "20", "60"], ["C", "30", "40"], ["D", "30", "40"]]
Output
[["10", "20", "A"], ["20", "30", "A,B"], ["30", "40", "A,B,C,D"], ["40", "50", "A,B"], ["50", "60", "B"]]
Explanation

The active set changes at times 10, 20, 30, 40, 50, and 60. Each returned row covers one maximal interval with a stable active set.

2Example 2

Input
rotations = [["A", "1", "3"], ["B", "5", "7"]]
Output
[["1", "3", "A"], ["5", "7", "B"]]
Explanation

The gap [3, 5) has nobody on call, so it is omitted.

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= rotations.length <= 2 * 10^5
  • Each row is [name, start, end].
  • 0 <= start < end <= 10^9
  • Multiple rotations may share the same start or end time.
public String[][] consolidateOnCallRotations(String[][] rotations) {
  // write your code here
}
Input

rotations

[["A", "10", "50"], ["B", "20", "60"], ["C", "30", "40"], ["D", "30", "40"]]

Output

[["10", "20", "A", "20", "30", "A", "B", "30", "40", "A", "B", "C", "D", "40", "50", "A", "B", "50", "60", "B"]]

Sign in to submit your solution.

Company OA Practice

Consolidate On-Call Rotations for Google online assessment prep

FastPrep catalogs Consolidate On-Call Rotations as a Google coding interview and online assessment practice problem. Review the prompt, examples, constraints, and nearby company problems together so the preparation context stays focused on Google OA patterns.