Job Sequencing Problem
Problem Statement
Each job takes exactly 1 unit of time, and only one job runs at a time. The time slots are 1, 2, 3, and so on.
A job earns its profit only if it finishes by its deadline. So job i must run in a slot that is at or before deadline[i].
Pick the set of jobs that earns the most profit in total. Return two numbers: how many jobs you picked, and the total profit.
Two arrays deadline and profit of the same length. Job i has deadline deadline[i] and profit profit[i].
A list [count, totalProfit]: the number of jobs picked for the maximum profit, and that maximum profit.
Job 1 (deadline 4, profit 20) and job 3 (deadline 1, profit 40) give 20 + 40 = 60. Only one job can use slot 1.
Job 1 (profit 100) and job 3 (profit 27) use slots 1 and 2. Total 127.
Jobs 1, 3 and 4 (50 + 20 + 30) fit in slots 3, 1 and 2.
- • The number of jobs is at most 10^5, and `deadline` and `profit` have the same length.
- • 1 ≤ deadline[i] ≤ n, where n is the number of jobs
- • 1 ≤ profit[i] ≤ 500
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Try every subset; keep the most profitable one that can run on time
Sort by profit (highest first); each job takes the latest free slot up to its deadline
Sort by deadline; keep a min-heap of profits; when it grows past the deadline, pop the smallest
There are 2^N subsets of jobs. For each subset, check whether it can run on time: sort its deadlines, and the k-th job (1-based) must have deadline ≥ k. Keep the feasible subset with the largest total profit, and report its size.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Greedy translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.