452. Minimum Number of Arrows to Burst Balloons

PHOTO EMBED

Thu Feb 23 2023 13:37:47 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

bool comp(vector<int>&x, vector<int>&y) //Custom comparator
{
    return x[1]<y[1];
}
class Solution {
public:
    int findMinArrowShots(vector<vector<int>>& points) {
        int n=points.size();
        if(n==0) return 0;
        if(n==1) return 1;
        
        sort(points.begin(),points.end(), comp);
        int prev=points[0][1];
        int no_ballon=1;
        for(int i=1;i<n;i++)
        {
            if(points[i][0]<=prev) continue;
            prev=points[i][1];
            no_ballon++;
        }
        return no_ballon;
    }
};
content_copyCOPY

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