FastPrepCombine Two Vectors of Intervals (MLE) πŸ™Œ

Combine Two Vectors of Intervals (MLE) πŸ™Œ

Meta logoMeta● MediumPHONE SCREENONSITE INTERVIEW

Updated

Problem statement

Imagine you have two vectors of intervals, labeled as X and Y, each representing a series of segments along a path. In vector X, there are no overlapping segments, and the same goes for vector Y. Your task is to merge these two vector into a single vector, ensuring that there are no overlaps in the resulting segments. However, you're asked to devise a highly efficient solution that outperforms naive methods.

Function

combineTwoVectorsOfIntervals(X: int[][], Y: int[][]) β†’ int[][]

Complete the function combineTwoVectorsOfIntervals in the editor πŸ‘‰.

Returns int[][]: The merged vector of intervals without any overlaps.

Examples

Example 1

X = [[1,5], [10,14], [16,18]]Y = [[2,6], [8,10], [11,20]]return = [[1,6], [8,20]]

The intervals from list X and list Y are merged and the overlapping intervals are combined to produce the following output:

  • The intervals [1,5] and [2,6] overlap and can be merged into [1,6].
  • The intervals [10,14] and [11,20] overlap with [8,10], and all can be merged into [8,20].
  • The interval [16,18] is within the bounds of [11,20] and is therefore already covered by it.

The resulting merged list of intervals with no overlaps is [[1,6], [8,20]].

Constraints

  • An unknown myth for now

More Meta Phone Screen questions

Similar questions at other companies

Meta interview experiences

All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int[][] combineTwoVectorsOfIntervals(int[][] X, int[][] Y) {
        // write your code here
    }

}
Checking account…