Minimum Number of Arrows to Burst Balloons
MediumP3Coding
Balloons are taped to a wall, and balloon i spans the horizontal range [xstart, xend] (its vertical position does not matter). An arrow shot straight up at position x bursts every balloon with xstart <= x <= xend, and keeps going. Return the minimum number of arrows needed to burst all balloons.
Example 1
- Input
- points = [[10,16],[2,8],[1,6],[7,12]]
- Output
- 2
- Why
- Shoot at x = 6 (bursts [2,8] and [1,6]) and at x = 11 (bursts [10,16] and [7,12]).
Example 2
- Input
- points = [[1,2],[3,4],[5,6],[7,8]]
- Output
- 4
Constraints
- 1 <= points.length <= 10^5
- -2^31 <= xstart < xend <= 2^31 - 1
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.