Widest Vertical Area Between Two Points Containing No Points

You are given `n` points on a 2D plane, where `points[i] = [xi, yi]`. Return the width of the **widest vertical area** between two points such that no point lies inside the area. A **vertical area** is a strip of fixed width that extends infinitely along the y-axis. Points on the edges of the strip do not count as inside it. The widest vertical area is the one with the largest width.

30:00

Widest Vertical Area Between Two Points Containing No Points
easy
Free written solution
Topics
Companies

You are given n points on a 2D plane, where points[i] = [xi, yi]. Return the width of the widest vertical area between two points such that no point lies inside the area.

A vertical area is a strip of fixed width that extends infinitely along the y-axis. Points on the edges of the strip do not count as inside it.

The widest vertical area is the one with the largest width.

Example 1:
Input: {"points":[[8,7],[9,9],[7,4],[9,7]]}
Output: 1
Constraints:
  • n == points.length

  • 2≤n≤1052 \leq n \leq 10^5

  • points[i].length == 2

  • 0≤xi,yi≤1090 \leq x_i, y_i \leq 10^9

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"points":[[8,7],[9,9],[7,4],[9,7]]}

A vertical strip ignores y entirely, so only the x coordinates matter. Project every point down onto the x axis.

points and empty vertical strips

x = 79

x values (not sorted yet)

8
9
7
9

widest so far

0

strip being measured
widest strip so far
point / its x on the axis
Variables
VariableValue
best0
DepthFunction Call
Stack empty
0/6