Widest vertical area between two points containing no points

November 20, 2022

array-and-hashmap

Problem URL: Widest vertical area between two points containing no points

We sort the points by x-coordinate, and find the maximum distance between two consecutive points.

class Solution:
    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:
        arr = sorted(x for x, y in points)
        return max(arr[i] - arr[i - 1] for i in range(1, len(arr)))

Time complexity: O(nlogn)
Space complexity: O(n)