FastPrepSmallest Point with Maximum Interval Coverage

Smallest Point with Maximum Interval Coverage

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Given a nonempty collection of closed integer intervals [left, right], return the smallest integer contained in the largest number of intervals.

An interval contains point when left <= point <= right. Count repeated intervals separately. A point interval [a,a] contains a. When several points have maximum coverage, choose the smallest.

Function

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

Examples

Example 1

intervals = [[2,13],[3,5],[1,4],[2,5]]return = 3

Both 3 and 4 lie in all four intervals. The specified smallest-point tie rule chooses 3.

Example 2

intervals = [[1,2],[2,4]]return = 2

The intervals share their closed endpoint 2, so its coverage is two.

Example 3

intervals = [[-3,-1],[0,2]]return = -3

The maximum coverage is one. The smallest covered integer is -3.

Constraints

  • 1 <= intervals.length <= 1000.
  • Each row has two integers with -1000000000 <= left <= right <= 1000000000.

More Meta problems

See Meta hiring insights
public int smallestMaximumOverlapPoint(int[][] intervals) {
    return 0;
}
intervals[[2,13],[3,5],[1,4],[2,5]]
expected3
Checking account…