EasyNo. 1637

Widest Vertical Area Between Two Points Containing No Points — LeetCode 1637 Python Solution

Pattern
Sorting
Topics
Array, Sorting
Reading time
2 min

The problem

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).

Example

Input
points = [[8,7],[9,9],[7,4],[9,7]]
Output
1
Explanation
Both the red and the blue area are optimal.

Python solution

PythonSolution
class Solution:
    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:
        points.sort()
        return max(b[0] - a[0] for a, b in pairwise(points))

Complexity

Time
O(n log n)
Space · auxiliary
O(1) to O(n)

Pattern: Sorting

Spend O(n log n) once to buy an ordering that makes the rest of the problem trivial. LeetCode 1637. Widest Vertical Area Between Two Points Containing No Points is filed here because LeetCode tags it Sorting, which is the vocabulary this hub collects.

The sorting guide has the Python template for the pattern and the 401 LeetCode problems that use it.

Related problems

Related problems
No.ProblemDifficulty
0056Merge IntervalsMedium
0164Maximum GapMedium
0274H-IndexMedium
0406Queue Reconstruction by HeightMedium
0414Third Maximum NumberEasy
0462Minimum Moves to Equal Array Elements IIMedium

Frequently asked questions

How hard is LeetCode 1637. Widest Vertical Area Between Two Points Containing No Points?

LeetCode 1637. Widest Vertical Area Between Two Points Containing No Points is rated Easy on LeetCode.

What topics does LeetCode 1637. Widest Vertical Area Between Two Points Containing No Points cover?

LeetCode 1637. Widest Vertical Area Between Two Points Containing No Points is tagged Array and Sorting on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.