Job Sequencing Problem
Each job takes 1 unit of time, has a deadline and a profit. Maximize profit by scheduling at most one job per slot, each before its deadline.
Open on GeeksforGeeks ↗Intuition
Take jobs in profit order — but place each as late as its deadline allows. Placing late keeps earlier slots free for jobs with tighter deadlines, so a rich job never squeezes out another it didn't have to.
Approach
Sort by profit, descending
If a job can be scheduled at all, we'd rather it be a high-profit one — commit to the richest first.
Place each in its latest free slot
For a job with deadline d, scan slots d, d−1, … 1 for a free one. Late placement preserves options for tighter jobs.
Optional speed-up
The slot scan can use a union-find 'next free slot' structure to reach O(n log n); the simple scan is O(n·maxD).
Solution & live demo
Edge cases
Only one slot exists — the single most profitable job is chosen.
Jobs failing to find a free slot are skipped, by construction the cheapest ones.