Problem · Array

Smallest Point with Maximum Inclusive Interval Overlap

Learn this problem
MediumGrab logoGrabNEW GRADPHONE SCREEN

Problem statement

Given a nonempty array of inclusive integer intervals [left, right], return the smallest integer point contained in the maximum number of intervals.

An interval contains x when left <= x <= right. Endpoints may be any signed 32-bit integer, including Integer.MAX_VALUE.

Function

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

Examples

Example 1

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

Point 4 belongs to all three intervals.

Example 2

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

The maximum overlap is one everywhere in the intervals, so the smallest covered point is -3.

Constraints

  • 1 <= intervals.length <= 100000.
  • Each row contains exactly two integers left <= right.
  • Endpoints are in the full signed 32-bit range.

More Grab problems

drafts saved locally
public int smallestMaximumOverlapPoint(int[][] intervals) {
    // Write your code here.
}
intervals[[1,4],[2,5],[4,6]]
expected4
checking account