All problems
0606MediumArrayGreedySorting

Fewest Inspection Mileposts

Tracked in this browser only
Write code

Trains the technique from

LeetCode 452Minimum Number of Arrows to Burst Balloons

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A rail operator has to sign off a list of track segments. The i-th entry of points gives that segment as a pair [start_i, end_i], meaning the segment covers every milepost from start_i to end_i with both ends included.

An inspection is booked at one integer milepost x. Booking it signs off every segment that covers x, so a segment is signed off when start_i <= x <= end_i. Any milepost may be chosen and any number of inspections may be booked.

Return the smallest number of inspections that signs off every segment on the list.

Examples

Example 1

Input
points = [[9, 12], [1, 3], [4, 8], [2, 5]]
Output
3

Booking mileposts 3, 8 and 12 signs off all four segments: milepost 3 covers [1, 3] and [2, 5], milepost 8 covers [4, 8], and milepost 12 covers [9, 12]. No pair of mileposts reaches all four.

Example 2

Input
points = [[1, 2], [2, 3]]
Output
1

Both segments cover milepost 2, since the ends of a segment are included, so a single booking there signs off both.

Example 3

Input
points = [[1, 10], [2, 3], [4, 5]]
Output
2

Booking milepost 3 signs off [1, 10] and [2, 3], and booking milepost 5 signs off [4, 5]. A single booking cannot cover both [2, 3] and [4, 5], which share no milepost.

Constraints

  • 1 <= points.length <= 10^5
  • points[i].length == 2
  • -2^31 <= start_i < end_i <= 2^31 - 1

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def find_min_arrow_shots(points: list[list[int]]) -> int:
Java
public int findMinArrowShots(int[][] points)
September 7
Apply