Standard Bar Greedy Approach · Medium O(n log n + n * maxDeadline) · O(maxDeadline)
A print shop takes single-slot commissions: each commission pays on completion and expires after its deadline slot. One commission runs per slot. The foreman ranks commissions by payout and slides each down the timeline, claiming the latest still-open slot at or before its deadline — the classic trick that keeps early slots free for tight-deadline work.
Input: A list of jobs, each [jobId, deadline, profit].
Output: Return [numberOfJobsDone, totalProfit] for the schedule that maximizes profit.
1 <= number of jobs <= 10^51 <= deadline <= 1001 <= profit <= 10^6Input: {"jobs":[[1,4,20],[2,1,10],[3,1,40],[4,1,30]]}
Output: [2,60]
Jobs 1 and 3 fill the two useful slots for 20 + 40 = 60.
Input: {"jobs":[[1,2,100],[2,1,19],[3,2,27],[4,1,25],[5,1,15]]}
Output: [2,127]
The 100-payout job takes slot 2, and the 27-payout job takes slot 1.