FastPrepMerge Meeting Intervals

Merge Meeting Intervals

Uber logoUber● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Given an unsorted array intervals of meeting intervals, return the maximal occupied spans after merging all overlaps.

For this exercise, assume each interval [start, end] represents the half-open span [start, end), with start < end. Coalesce touching spans as well as overlapping spans: [1,3) and [3,5) produce [1,5), because their union has no gap.

Return the merged spans in increasing start order. Every returned span must be maximal, so consecutive returned spans satisfy previousEnd < nextStart. Duplicate or nested intervals do not add separate output spans. An empty input returns an empty array.

This is an occupied-time summary, not room allocation: do not discard, shorten, reschedule or cancel any meeting. Preserve the input array.

Function

mergeMeetingIntervals(intervals: int[][]) → int[][]

Examples

Example 1

intervals = [[5,7],[1,4],[3,6],[10,12]]return = [[1,7],[10,12]]

The first three intervals connect through overlaps and cover [1,7). The span [10,12) remains separate because there is a gap.

Example 2

intervals = [[0,2],[2,5]]return = [[0,5]]

The intervals touch at 2. Their union is the single half-open span [0,5).

Example 3

intervals = []return = []

There is no occupied time to summarize.

Constraints

  • 0 <= intervals.length <= 200.
  • Each interval contains exactly two signed-32-bit integers with -2147483648 <= start < end <= 2147483647.
  • All ordering, endpoint coalescing, empty-input and input-preservation rules are part of this practice contract.

More Uber problems

See Uber hiring insights
public int[][] mergeMeetingIntervals(int[][] intervals) {
    // Write your code here.
}
intervals[[5,7],[1,4],[3,6],[10,12]]
expected[[1,7],[10,12]]
Checking account…