Problem · Intervals

Find Overlapping Times

Learn this problem
EasyAmazonINTERNOA
See Amazon hiring insights

Problem statement

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

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

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

Examples

Example 1

intervals = [[7, 7], [2, 3], [6, 11], [1, 2]]return = [[1, 3], [6, 11]]
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

  • 1 ≤ n ≤ 10^5
  • 1 ≤ intervals[i][2] ≤ 10^9
  • intervals[i][0] ≤ intervals[i][1] for all i.
  • More Amazon problems

    drafts saved locally
    public int[][] findOverlappingTimes(int[][] intervals) {
      // write your code here
    }
    
    intervals[[7, 7], [2, 3], [6, 11], [1, 2]]
    expected[[1, 3], [6, 11]]
    checking account