AlgoMaster Logo

Minimum Number of Arrows to Burst Balloons

points=[[10,16],[2,8],[1,6],[7,12]]
1def findMinArrowShots(points):
2    points.sort(key=lambda x: x[1])
3
4    arrows = 1
5    current_end = points[0][1]
6
7    for i in range(1, len(points)):
8        current_balloon = points[i]
9
10        if current_balloon[0] <= current_end:
11            # Current arrow can burst this balloon
12            continue
13        else:
14            # Need a new arrow
15            arrows += 1
16            current_end = current_balloon[1]
17
18    return arrows
0 / 9
[10,16][2,8][1,6][7,12]burst