Widest Vertical Area Between Two Points Containing No Points

Given n points on a 2D plane where points[i] = [xi, yi], return the widest vertical area between two points such that no points are inside the area.

A vertical area is an area of fixed width extending infinitely along the y-axis, meaning it has infinite height. The widest vertical area is the one with the maximum width.

Note that points on the edge of a vertical area are not considered included in the area.

Example 1
Inputpoints = [[8,7],[9,9],[7,4],[9,7]]
Output1
Both the red and the blue area are optimal, and the maximum width is 1.
Example 2
Inputpoints = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
Output3
After sorting the x-coordinates, the largest gap between adjacent x-values is 3.

Constraints

  • n == points.length
  • 2 <= n <= 10^5
  • points[i].length == 2
  • 0 <= xi, yi <= 10^9

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate