Balloons hang above a straight number line. Balloon i covers the stretch points[i] = [startᵢ, endᵢ]. An arrow fired straight up from position x bursts every balloon with startᵢ <= x <= endᵢ, including one whose edge is exactly at x, and keeps flying after it does.
Return the fewest arrows that burst every balloon.
One arrow at 3 bursts [1,3] and [2,6]. One at 8 bursts [7,8] and [5,10]. [12,14] is far from the rest and needs its own arrow.
An arrow at 2 touches the edges of the first two balloons, so it bursts both. A second arrow at 5 or anywhere up to 9 finishes the job.
No two balloons share a point, so each one takes an arrow.
Constraints
1 <= points.length <= 10⁵points[i].length == 2-2³¹ <= startᵢ < endᵢ <= 2³¹ - 1Look at the balloon that ends first. Some arrow has to hit it, and firing at its right edge is never worse than firing further left: that spot still reaches every balloon that has already started.
Look at the balloon that ends first, the one with the smallest end. Some arrow has to burst it, so some arrow flies somewhere between its start and its end. Where is the best place for that arrow? As far right as it can go: at that balloon's end.
Time O(n log n)Space O(n)
The full walkthrough and code are part of Premium
3