Leetcode Problem 1235. Maximum Profit in Job Scheduling
1235. Maximum Profit in Job Scheduling
Leetcode Solutions
Sorting + Priority Queue
Create a list of jobs where each job is a tuple of (startTime, endTime, profit).
Sort the jobs by their start times.
Initialize a priority queue (min-heap) to store job chains as pairs of (end time, total profit).
Initialize a variable maxProfit to keep track of the maximum profit seen so far.
Iterate over the sorted jobs, and for each job:
a. While the job chain at the top of the priority queue conflicts with the current job, pop it from the queue.
b. Update maxProfit with the profit of the popped job chain if it's higher.
Push the current job into the priority queue with its end time and the profit obtained by adding its profit to maxProfit.
After iterating over all jobs, return the value of maxProfit.