Skip to content
StackDecode
GreedyAnimated

Job Sequencing with Deadlines

Do the highest-profit jobs, each in the latest free slot before its deadline.

Time

O(n log n)

Extra space

O(n)

Use it for

Scheduling for maximum profit.

How it works

  1. Each job takes one time slot and must finish by its deadline to earn its profit.
  2. Consider jobs from highest profit to lowest.
  3. Put each job in the latest free slot at or before its deadline (this keeps earlier slots open for tighter jobs). If no slot is free, drop the job.
  4. O(n log n) with sorting (O(n²) with the plain slot scan shown here).

Watch it run

Loading animation…