aboutsummaryrefslogtreecommitdiff
path: root/widest_vert_two_point.py
blob: 36c19de67c5ea87fdc4b3c38c50670b40661d3e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 1637. Widest Vertical Area Between Two Points Containing No Points

"""
given 'n' points on a 2d plane where 'points [i] = [x[i], y[i]]', return the
widest veritcal 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. the widest vertical area is the one with the maximum width. note
that the points on the edge of a vertical area are not considred included in
the area.
"""


class Solution(object):
    def maxWidthOfVerticalArea(self, points):
        """
        :type points: List[List[int]]
        :rtype: int
        """
        area = sorted({x for x, y in points})
        return max([b - a for a, b in zip(area, area[1:])] + [0])


if __name__ == "__main__":
    obj = Solution()
    print(
        obj.maxWidthOfVerticalArea(points=[[8, 7], [9, 9], [7, 4], [9, 7]])
    )  # expect: 1
    print(
        obj.maxWidthOfVerticalArea(
            points=[[3, 1], [9, 0], [1, 0], [1, 4], [5, 3], [8, 8]]
        )
    )  # expect: 3