Minimum Number of Arrows to Burst Balloons

Medium Greedy Sorting

Problem

Balloons are closed intervals on a number line. An arrow shot at point x bursts every balloon whose interval contains x. Return the fewest arrows needed to burst every balloon.

Original: LeetCode 452: Minimum Number of Arrows to Burst Balloons.

Examples

Example 1

Input`points = [[10, 16], [2, 8], [1, 6], [7, 12]]`
Output`2`

Example 2

Input`points = [[1, 2], [3, 4], [5, 6], [7, 8]]`
Output`4`

Example 3

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

Constraints

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

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (2)
  1. LeetCode 452: Minimum Number of Arrows to Burst Balloonsleetcode.com
  2. Java SE 17 API: Integer.comparedocs.oracle.com