mediumGreedySortingGreedy

Minimum Number of Arrows to Burst Balloons

mediumTime: O(n log n)Space: O(1)

Signals to notice

minimum arrows to burst all balloonsoverlapping intervalsone arrow pops all overlapping

Brute force first

Try all arrow positions. Test every possible x-coordinate. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.

The key insight

Sort by end coordinate. Shoot at each balloon's end. Skip all balloons that overlap with this shot. Count arrows. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.

What must stay true

Shooting at a balloon's end maximizes the chance of hitting overlapping balloons to the right. If the next balloon starts after the shot, it needs a new arrow. If that remains true after every update, the rest of the reasoning has a stable place to stand.

Easy way to go wrong

Sorting by start instead of end — end-sorting ensures the greedy choice covers the maximum number of subsequent overlapping balloons. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.

Greedy Pattern