FastPrepFastPrep
Problem Brief

Find Overlapping Times

INTERNOA

AMZ Interval Collection (A group of problems focused on operations involving intervals :) -

1. Find Overlapping Times (Intern)

2. Get Maximum Sum Find Overlapping Times (Full-Time)

3. Merge Intervals (Intern, NG)

4. Task Scheduler (Full-Time)

5. Optimal Interval Difference

At an Amazon warehouse, trucks follow scheduled arrival and departure times. Each truck's timeframe is represented as an interval [arrival, departure], where it marks when the truck entered and exited the facility.

Due to operational overlaps, some intervals may intersect, meaning multiple trucks were at the warehouse at the same time. To simplify the records, overlapping intervals should be merged into a single continuous time block.

Your task is to process a list of time intervals, merge any overlapping ones, and return the final set of intervals sorted in ascending order of arrival times.

Function Description

Complete the function findOverlappingTimes in the editor.

findOverlappingTimes has the following parameter(s):

  1. int intervals[[n][2]]: the time intervals

Returns

int[][2]: the merged intervals in sorted order

1Example 1

Input
intervals = [[7, 7], [2, 3], [6, 11], [1, 2]]
Output
[[1, 3], [6, 11]]
Explanation
The interval [1, 2] merges with [2, 3] while [7, 7] merges with [6, 11]. There are no more overlapping intervals. The answer is [[1, 3], [6, 11]].

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≤ n ≤ 10^5
  • 1 ≤ intervals[i][2] ≤ 10^9
  • intervals[i][0] ≤ intervals[i][1] for all i.
  • public int[][] findOverlappingTimes(int[][] intervals) {
      // write your code here
    }
    
    Input

    intervals

    [[7, 7], [2, 3], [6, 11], [1, 2]]

    Output

    [[1, 3], [6, 11]]

    Sign in to submit your solution.