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
Understanding the Visualization
1
Input
Balloons with horizontal ranges [[10,16],[2,8],[1,6],[7,12]]
2
Process
Sort by end position and greedily place arrows
3
Output
Minimum arrows needed: 2
Key Takeaway
🎯 Key Insight: Sort balloons by end position, then greedily place arrows at optimal positions to cover maximum overlapping balloons
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code