TRT
Sign in
mediumAdvancedLeetCode#earliest end first

Minimum number of arrows to burst balloons

Shoot the fewest arrows to burst every horizontal balloon, shooting at the earliest end each time.

The Runtime Theory Team1 min read
Taught inScheduling and intervalsPro — members onlyTo fit the most non-overlapping intervals, always take the one that ends first. A 'greedy stays ahead' proof shows why, and the same rule solves a family of removal, arrow and partition problems.
Solve it

Solving happens on the judge — come back and mark it done

Sample cases

inpoints = [[10, 16], [2, 8], [1, 6], [7, 12]]

out2

inpoints = [[1, 2], [3, 4], [5, 6], [7, 8]]

out4

inpoints = [[1, 2], [2, 3], [3, 4], [4, 5]]

out2

Balloons are intervals on the x-axis. An arrow shot at x bursts every balloon with start ≤ x ≤ end. Return the minimum number of arrows.

Before you code

The balloon that ends first must be hit by some arrow at or before its end. Shooting exactly at its end hits it and as many others as possible.

Hints

  1. Sort by end.
  2. Shoot at the first balloon's end; skip every balloon whose start is at most that point.
  3. Shoot again at the next unburst balloon's end. Note that touching counts here: closed intervals.

Production & complexity notes

When solving Minimum number of arrows to burst balloons on LeetCode (medium), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Scheduling and intervals to reinforce the underlying pattern.

What it practices

The earliest-end rule in another form, from Scheduling and intervals.

Not started

Sign in to save your learning progress.

Sign in to save