#1637
Easy Algorithms Widest vertical area between two points containing no points
Array Sorting
87.1% acceptance
Feb 25, 2026
982
1788
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. 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.
Solution
Rust
Time O(n log n)
Space O(1)
impl Solution {
pub fn max_width_of_vertical_area(points: Vec<Vec<i32>>) -> i32 {
let mut xs: Vec<i32> = points.iter().map(|p| p[0]).collect();
xs.sort();
xs.dedup();
xs.windows(2).map(|w| w[1] - w[0]).max().unwrap_or(0)
}
}