Minimum Number of Arrows to Burst Balloons

Problem Id: 452 Difficulty: Medium


Intuition

Solution


class Solution(object):
    def findMinArrowShots(self, points):
        """
        :type points: List[List[int]]
        :rtype: int
        """
        if len(points) <= 1:
            return len(points)

        points.sort()
        ans = 1
        index = 1
        start, end = points[0]
        while index < len(points):
            s2, e2 = points[index]
            if end < s2:
                ans += 1
                start, end = s2, e2
            else:
                start, end = s2, min(e2, end)
            index += 1
        return ans