↓Skip to main content
  1. LeetCode/

LeetCode 452: Minimum Number of Arrows to Burst Balloons

·2 mins· ·
LeetCode Medium Array Greedy Sorting
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: medium First Attempt: 2026-11-03

  • Submissions: Accepted (first try)

Approach
#

Sort by end (Greedy Template 2). Shoot the first arrow at the end of the first balloon: the further right, the more later balloons it can hit, but it cannot go past this balloon’s end.

Moving on, a balloon whose start is <= the arrow position is hit by that arrow; a start > the arrow position needs a new arrow, shot at that balloon’s end.

It is almost LC 435; only the boundary differs. Balloons are closed intervals, so [1,2] and [2,3] both burst with one arrow at 2: touching ends overlap and the test is >. In LC 435 touching ends do not overlap and the test is >=.

My Attempts
#

Accepted on the first try. Having just written LC 435, I only had to change >= to >.

Solution
#

class Solution:
    def findMinArrowShots(self, points: List[List[int]]) -> int:
        points.sort(key=lambda x: x[1])
        arrows, pos = 0, float("-inf")
        for start, end in points:
            if start > pos:           # current arrow misses, shoot a new one at the end
                arrows += 1
                pos = end
        return arrows

Complexity
#

Time O(n log n), space O(1) apart from sorting.

Mistakes to Avoid
#

  • Copying >= from LC 435: [[1,2],[2,3]] returns 2; the answer is 1.
  • When sorting by start, shrink the arrow position to min(pos, end) on overlap, or balloons with a smaller end are missed. Sorting by end avoids this.

Interview Explanation
#

I sort by end and shoot every arrow at the current balloon’s end, which hits as many later balloons as possible. Scanning forward, a balloon whose start does not pass the arrow is hit; otherwise I shoot another arrow at that balloon’s end. Touching ends overlap, so the test is strictly greater, not greater-or-equal. Time O(n log n).

Related

LeetCode 948: Bag of Tokens
·2 mins
LeetCode Medium Two-Pointers Greedy Sorting Array
LeetCode 948 note: after sorting, buy score with the cheapest token and buy power with the most expensive one; trade for power only when score > 0, and stop when neither move works
LeetCode 3413: Maximum Coins From K Consecutive Bags
·3 mins
LeetCode Medium Sliding-Window Greedy Sorting Prefix-Sum Binary-Search Array
LeetCode 3413 note: the best k bags always have one end on a segment boundary; compute “left end at a segment start” and “right end at a segment end” (the latter by mirroring and reusing the same function)
LeetCode 3627: Maximum Median Sum of Subsequences of Size 3
·2 mins
LeetCode Medium Math Greedy Sorting Game-Theory Array
LeetCode 3627 note: after sorting, each group takes the two largest and the smallest, with the second largest as the median; the answer takes every other value from the end, n / 3 of them
LeetCode 3075: Maximize Happiness of Selected Children
·1 min
LeetCode Medium Array Greedy Sorting
LeetCode 3075 note: choose k children from the happiest, where the i-th choice loses i, floored at 0
LeetCode 324: Wiggle Sort II
·2 mins
LeetCode Medium Array Divide-and-Conquer Greedy Sorting
LeetCode 324 note: sort, split into a small half and a large half, reverse each, and interleave with small values at even indices and large ones at odd indices
LeetCode 435: Non-overlapping Intervals
·3 mins
LeetCode Medium Array Dynamic-Programming Greedy Sorting
LeetCode 435 note: minimum removals = total minus the maximum kept; sort by right end and greedily keep the one ending earliest