Untitled
plain_text
a month ago
797 B
2
Indexable
Never
public class Solution { public int solve(int[][] A) { //sort based on end and pick non-overlappng jobs. //TC: O(nlogn) //SC: O(1) int n = A.length; //sort Arrays.sort(A, new Comparator<int[]>(){ @Override public int compare(int[] a, int[] b){ if(a[1]<b[1]){ return -1; }else if(a[1]>b[1]){ return 1; }else{ return 0; } } }); int count=0; int end=0; for(int i=0;i<n;i++){ if(A[i][0] > end){ //pick the job. end=A[i][1]; count++; } } return count; } }