All problems
Minimum Arrows to Burst Balloons
Problem
Given balloons as [start, end] horizontal spans, return the minimum number of arrows needed to burst all of them, where an arrow at position x bursts every balloon whose span contains x.
Sort by right endpoint and shoot an arrow at the end of the first unburst balloon, skipping every balloon that this arrow covers. Return 0 for no balloons.
Hint
Shooting at the earliest finishing end covers as many later balloons as possible.
Test cases
case 1
in: [[[10,16],[2,8],[1,6],[7,12]]]
expected: 2
case 2
in: [[[1,2],[3,4],[5,6],[7,8]]]
expected: 4
case 3
in: [[[1,2]]]
expected: 1
case 4
in: [[[2,3],[1,2]]]
expected: 1
case 5
in: [[]]
expected: 0
Starter codePython
def min_arrows_balloons(points):
# Your code here
pass5 test cases · run your code against them in the editor