Greedy The best choice now
505. Minimum Number of Arrows to Burst Balloons
Some balloons hang above a straight line, the x-axis. You are given an array points, where
points[i] = [xstart, xend] means that balloon i stretches over every position from xstart to xend.
An arrow shot straight up from position x bursts every balloon with xstart ≤ x ≤ xend. The arrow keeps
flying after it bursts a balloon, so one arrow can burst many. Return the fewest arrows you need to burst every
balloon.
An arrow that only touches the edge of a balloon still bursts it. So an arrow at 5 bursts both [2,5] and
[5,9]. A balloon can also be a single point, with xstart = xend.
Example 1
Input: points = [[3, 8],
[1, 4],
[10, 14],
[7, 11],
[9, 12]]
2Explanation: An arrow at 4 bursts [1,4] and [3,8], and an arrow at 11 bursts [7,11], [9,12] and [10,14]. No
position lies inside all five balloons, so one arrow is not enough.
Example 2
Input: points = [[2, 5], [5, 9], [9, 12], [12, 15]]
2Explanation: An arrow at 5 bursts the first two balloons, which touch there. An arrow at 12 bursts the other two.
Example 3
Input: points = [[2147483647, 2147483647],
[-2147483648, -2147483648]]
2Explanation: Each balloon is a single point, one at each end of the range, so each one needs its own arrow.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ points.length ≤ 105points[i].length = 2-231 ≤ xstart ≤ xend ≤ 231 − 1
Clarifying questions
What you would ask an interviewer before writing any code.