Optimizing Job Scheduling For Maximum Profit
Sort jobs by profit in descending order, then schedule as close to deadline as possible. Use a slot array to keep track of assigned jobs and maximize profit.
Problem
class Solution {
// sort on the basis of profit in descending order and try to execute the jobs as close to their deadline as possible
ArrayList<Integer> JobScheduling(Job jobs[], int n) {
// Your code here
Arrays.sort(jobs,(a,b)-> b.profit-a.profit);
int maxDeadline= -1;
for(int i=0;i<jobs.length;i++){
maxDeadline = Math.max(maxDeadline, jobs[i].deadline);
}
int slots[] = new int[maxDeadline];
Arrays.fill(slots,-1);
int profit = 0;
int noOfJobs = 0;
for(int i =0;i<jobs.length;i++){...