Skip to content

Commit 395be78

Browse files
authored
Create 1637_Widest_Vertical_Area_Between_Two_Points_Containing_No_Points.md
1 parent ef72660 commit 395be78

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## 1637. Widest Vertical Area Between Two Points Containing No Points
2+
3+
Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area.
4+
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.
5+
Note that points on the edge of a vertical area are not considered included in the area.
6+
7+
8+
```
9+
Example 1:
10+
Input: points = [[8,7],[9,9],[7,4],[9,7]]
11+
Output: 1
12+
Explanation: Both the red and the blue area are optimal.
13+
Example 2:
14+
15+
Input: points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
16+
Output: 3
17+
```
18+
19+
20+
21+
```python
22+
def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:
23+
# d = 0
24+
xs = sorted([x for x, _ in points])
25+
# for i in range (len(xs)-1):
26+
# if d < xs[i+1]-xs[i]:
27+
# d = xs[i+1]-xs[i]
28+
# return d
29+
return max(xs[i+1]-xs[i] for i in range(len(xs)-1))
30+
```
31+
32+
33+
```
34+
Runtime: 808 ms, faster than 93.33% of Python3 online submissions for Widest Vertical Area Between Two Points Containing No Points.
35+
Memory Usage: 54.5 MB, less than 90.11% of Python3 online submissions for Widest Vertical Area Between Two Points Containing No Points.
36+
```

0 commit comments

Comments
 (0)