452. Minimum Number of Arrows to Burst Balloons
Practice Minimum Number of Arrows to Burst Balloons for free on NudgeCode: Medium, Greedy pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Each balloon is a closed interval [start, end] on the x-axis. An arrow shot straight up at position x bursts every balloon with start <= x <= end, and keeps flying, so one arrow can burst many balloons.
Given the balloons in points, return the smallest number of arrows that bursts all of them. Balloons that only touch at an end point, like [1,2] and [2,3], can share one arrow at x = 2.
Example
points = [[10,16],[2,8],[1,6],[7,12]] -> 2
points = [[1,2],[2,3],[3,4],[4,5]] -> 2
In the first case, one arrow at x = 6 bursts [2,8] and [1,6], and one at x = 11 bursts [10,16] and [7,12].
Constraints
- 1 <= points.length <= 10^5
- -2^31 <= start <= end <= 2^31 - 1