I am not able to get the correct answer for the folowing question . I saw other approaches but i want to see the mistake i did .I used greedy method to solve the question .Can anyone tell what is wrong with the code ? please...it would be really helpfull.Here is the link to the question - https://practice.geeksforgeeks.org/problems/job-sequencing-problem-1587115620/1
int[] JobScheduling(Job arr[], int n)
{
    ArrayList<Job> l = new ArrayList<>();
    for(int i =0;i<arr.length ;i++){
        l.add(arr[i]);
    }
    Collections.sort(l, (a,b)-> b.profit-a.profit);
    
    int time = 0;
    int profit =0;
    int jobDone =0;
    for(int i =0; i<l.size();i++){
        Job j = l.get(i);
        if(j.deadline > time){
            jobDone++;
            profit += j.profit;
        }
    }
    int res[] = new int[2];
    int flag =0;
    res[flag++] = jobDone;
    res[flag++] = profit;
    return res;
}
 
    