class pair implements Comparable<pair>{
int x, y;
pair(int x, int y){
this.x = x;
this.y = y;
}
public int compareTo(pair c){
return this.y-c.y;
}}
class Solution {
public int findMinArrowShots(int[][] points) {
ArrayList<pair> point = new ArrayList<>();
for(int i=0; i<points.length; i++){
point.add(new pair(points[i][0], points[i][1]));
}
Collections.sort(point);
int minarr=1;
int prev =0;
for(int i=1; i<point.size(); i++){
if(point.get(i).x>point.get(prev).y){
minarr++;
prev = i;
}
}
return minarr;
}}
I want to sort the array on the basis of y coordinate: but with mix of positive and negative y values it is giving me wrong(unsorted) order
for eg: for the I/P : [[-2147483646,-2147483645], [2147483646,2147483647]] I need [-2147483646,-2147483645] first then [2147483646,2147483647] but it is ordering [2147483646,2147483647] as first then [-2147483646,-2147483645].