Minimum Number of Arrows to Burst Balloons

Medium Topics Company Tags

Each entry [start, end] in points describes the horizontal span of a balloon. An arrow fired vertically at coordinate x bursts every balloon satisfying start <= x <= end, including balloons touched at an endpoint. Arrows continue indefinitely, so one shot can burst multiple balloons. Return the fewest arrows needed to burst them all.

Example 1:

Input: points = [[0,3],[3,6]]

Output: 1

Explanation: Shoot at x=3. Both balloons include that endpoint, so one arrow bursts them both.

Example 2:

Input: points = [[1,2],[4,5],[8,9]]

Output: 3

Explanation: These three spans are disjoint. No arrow can hit more than one, so 3 arrows are necessary.

Example 3:

Input: points = [[-5,5],[-2,1],[0,3]]

Output: 1

Explanation: The coordinate x=0 lies inside every span. One arrow there bursts all three balloons.

Constraints:

  • 1 <= points.length <= 100000
  • Every balloon is described by exactly two integers.
  • -2147483648 <= start < end <= 2147483647


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.