Minimum Number of Arrows to Burst Balloons - Problem

You are given points where points[i] = [x_start, x_end] represents balloons whose horizontal diameter stretches between x_start and x_end. You do not know the exact y-coordinates of the balloons.

Arrows can be shot up directly vertically (in the positive y-direction) from different points along the x-axis. A balloon with x_start and x_end is burst by an arrow shot at x if x_start <= x <= x_end. There is no limit to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path.

Given the array points, return the minimum number of arrows that must be shot to burst all balloons.

Input & Output

Example 1 — Basic Overlapping Case
$ Input: points = [[10,16],[2,8],[1,6],[7,12]]
Output: 2
💡 Note: After sorting by end position: [[1,6],[2,8],[7,12],[10,16]]. First arrow at position 6 bursts [1,6] and [2,8]. Second arrow at position 12 bursts [7,12] and [10,16].
Example 2 — All Overlapping
$ Input: points = [[1,2],[3,4],[5,6],[7,8]]
Output: 4
💡 Note: No balloons overlap, so we need one arrow for each balloon: 4 arrows total.
Example 3 — Single Balloon
$ Input: points = [[1,2]]
Output: 1
💡 Note: Only one balloon, so we need exactly one arrow to burst it.

Constraints

  • 1 ≤ points.length ≤ 105
  • points[i].length == 2
  • -231 ≤ xstart < xend ≤ 231 - 1

Visualization

Tap to expand
Minimum Number of Arrows to Burst Balloons INPUT x [1,6] [2,8] [7,12] [10,16] 1 6 7 10 12 16 Input Array: [[10,16],[2,8],[1,6],[7,12]] 4 balloon intervals on x-axis Arrows shot vertically ALGORITHM STEPS 1 Sort by End Point Sort intervals by x_end [1,6],[2,8],[7,12],[10,16] 2 First Arrow at x=6 Bursts [1,6] and [2,8] Arrow 1 3 Second Arrow at x=12 Bursts [7,12] and [10,16] Arrow 2 4 Count Arrows Total arrows needed = 2 Greedy: Always shoot at end point FINAL RESULT x [1,6] [2,8] x=6 [7,12] [10,16] x=12 OUTPUT 2 All 4 balloons burst! Arrow 1 at x=6: bursts 2 Arrow 2 at x=12: bursts 2 OK Key Insight: Sort balloons by their END position. For each balloon, shoot at its end point to maximize overlap with subsequent balloons. Skip balloons already burst. This greedy approach ensures minimum arrows because each arrow bursts the maximum possible consecutive overlapping balloons. TutorialsPoint - Minimum Number of Arrows to Burst Balloons | Greedy with Sorting
Asked in
Microsoft 25 Amazon 20 Google 15
125.0K Views
Medium Frequency
~15 min Avg. Time
2.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen