Ctrl K

Widest Empty Strip

Easy
Trees grow in a forest, and tree i stands at the point trees[i] = [x, y]. The rangers want to cut a vertical firebreak: a strip between two vertical lines, endless upward and downward, with no tree strictly inside it. Trees standing exactly on the edge of the strip are fine. Each edge of the firebreak must pass through some tree. Return the greatest possible width of such a strip.
Example 1
trees=[[6, 2], [1, 5], [9, 9], [3, 0]] → 3

The x coordinates in order are 1, 3, 6, 9. The widest gap lies between 3 and 6, and its width is 3.

Example 2
trees=[[4, 1], [4, 8], [5, 3]] → 1

Two trees share the vertical line x = 4, so there is no strip between them. That leaves the gap from 4 to 5, of width 1.

Example 3
trees=[[0, 0], [10, 10], [2, 7], [8, 1]] → 6
Constraints
  • 2 ≤ len(trees) ≤ 10⁵
  • len(trees[i]) == 2
  • 0 ≤ x, y ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMerge Into the Spare Tail EasyThe Candidate With Most Votes EasyDoes Any Value Repeat EasyMake It to Every Meeting EasyThe Lost Ticket Easy
loading Python…
Input
trees=[[6, 2], [1, 5], [9, 9], [3, 0]]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 104 tests on the server, hidden ones included.