DEV Community

Debesh P.
Debesh P.

Posted on

452. Minimum Number of Arrows to Burst Balloons | LeetCode | Top Interview 150 | Coding Questions

Problem Link

https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/


Detailed Step-by-Step Explanation

https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/solutions/7540732/most-optimal-solution-all-languages-avai-47ic


leetcode 452


Solution

class Solution {
    public int findMinArrowShots(int[][] points) {

        int n = points.length;
        if (n == 0) return 0;
        Arrays.sort(points, (a, b) -> Integer.compare(a[1], b[1]));

        int arrows = 1;
        int end = points[0][1];

        for (int i = 1; i < n; i++) {
            if (points[i][0] > end) {
                arrows++;
                end = points[i][1];
            }
        }

        return arrows;
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)