Widest Vertical Area Between Two Points Containing No Points

Easy Topics Company Tags

Each entry of points gives an [x, y] coordinate. Choose two vertical lines passing through x-coordinates present in the input. The strip between them extends infinitely upward and downward and must contain no input point strictly inside it; points on either boundary are allowed. Return the largest possible strip width. If all points share one x-coordinate, return 0.

The hatched band shows a widest vertical gap between point coordinates.

Example 1:

Widest Vertical Area Between Two Points Containing No Points, example 1: illustration of the example

Input: points = [[1,4],[6,0],[10,8]]

Output: 5

Explanation: The empty strips run from x=1 to x=6 and from x=6 to x=10, with widths 5 and 4. The widest has width 5; the y-coordinates do not limit its infinite height.

Example 2:

Widest Vertical Area Between Two Points Containing No Points, example 2: illustration of the example

Input: points = [[3,0],[3,9],[3,4]]

Output: 0

Explanation: Every point has x=3. There are no two distinct boundary x-coordinates, so the width is 0.

Example 3:

Widest Vertical Area Between Two Points Containing No Points, example 3: illustration of the example

Input: points = [[0,2],[8,5],[8,1],[11,0]]

Output: 8

Explanation: The strip from x=0 to x=8 has width 8 and contains no point strictly inside. Both points at x=8 are on its boundary and are allowed.

Constraints:

  • 2 <= points.length <= 100000
  • Each point contains exactly two integers: [x, y].
  • 0 <= x, y <= 1000000000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.