Widest Vertical Area Between Two Points Containing No Points Problem
Description
LeetCode Problem 1637.
Given n points on a 2D plane where points[i] = [x_i, y_i], 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 (i.e., 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:

Input: points = [[8,7],[9,9],[7,4],[9,7]]
Output: 1
Explanation: Both the red and the blue area are optimal.
Example 2:
Input: points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
Output: 3
Constraints:
n == points.length2 <= n <= 10^5points[i].length == 20 <= x_i, y_i <= 10^9
Solution
Approach: Sort the x-Coordinates
A vertical area is a strip between two vertical lines, and it is endlessly tall, so the y-coordinates do not matter at all. A strip contains no points exactly when no x-coordinate lies strictly between its two sides. The widest such strip therefore runs between two x-coordinates that are next to each other in sorted order.
So collect the x-coordinates, sort them, and return the largest difference between neighbors.
Points with the same x give a difference of 0, which is right: there is no room between them. And since points on the edge do not count as inside, a strip can always start and end at points.
Complexity: O(n log n) time for sorting, O(n) extra space for the x-coordinates.
class Solution:
def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:
xs = sorted(x for x, _ in points) # only the x-coordinates matter
return max(b - a for a, b in zip(xs, xs[1:]))