[LeetCode] Widest Vertical Area Between Two Points Containing No Points

1637. Widest Vertical Area Between Two Points Containing No Points

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.

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.

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
int maxWidthOfVerticalArea(vector<vector<int>>& A) {
sort(begin(A), end(A));
int res = 0, n = A.size();
for(int i = 0; i < n-1; i++) {
res = max(res, A[i+1][0] - A[i][0]);
}
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/07/07/PS/LeetCode/widest-vertical-area-between-two-points-containing-no-points/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.