Job sequencing Problem

Greedy Algorithms Scheduling and Interval Problems Medium
  • This type of problem is commonly encountered in project management and scheduling software applications
  • For instance, software that manages tasks and deadlines in industries such as manufacturing, supply chain, or software development often needs to optimise schedules based on profit and deadlines
  • This involves choosing an order to execute jobs in a way that maximises profit while respecting deadlines — a real-world application of the job scheduling problem

Given an 2D array Jobs of size Nx3, where Jobs[i][0] represents JobID , Jobs[i][1] represents Deadline , Jobs[i][2] represents Profit associated with that job. Each Job takes 1 unit of time to complete and only one job can be scheduled at a time.


The profit associated with a job is earned only if it is completed by its deadline. Find the number of jobs and maximum profit.

Examples:

Input : Jobs = [ [1, 4, 20] , [2, 1, 10] , [3, 1, 40] , [4, 1, 30] ]

Output : 2 60

Explanation : Job with JobID 3 can be performed at time t=1 giving a profit of 40.

Job with JobID 1 can be performed at time t=2 giving a profit of 20.

No more jobs can be scheduled, So total Profit = 40 + 20 => 60.

Total number of jobs completed are two, JobID 1, JobID 3.

So answer is 2 60.

Input : Jobs = [ [1, 2, 100] , [2, 1, 19] , [3, 2, 27] , [4, 1, 25] , [5, 1, 15] ]

Output : 2 127

Explanation : Job with JobID 1 can be performed at time time t=1 giving a profit of 100.

Job with JobID 3 can be performed at time t=2 giving a profit of 27.

No more jobs can be scheduled, So total Profit = 100 + 27 => 127.

Total number of jobs completed are two, JobID 1, JobID 3.

So answer is 2 127.

Input : Jobs = [ [1, 1, 100] , [2, 2, 200] , [3, 3, 300] , [4, 4, 400] ]

Constraints

  • 1 <= N <= 105
  • 1 <= Deadline <= N
  • 1 <= Profit <= 500

Hints

  • Maintain a timeline (e.g., a list of size equal to the maximum deadline) to keep track of which time slots are occupied. For each job, attempt to schedule it at the latest available time slot before its deadline. If no such slot exists, skip the job.
  • Keep a count of the number of successfully scheduled jobs. Add the profit of each scheduled job to the total profit. At the end, return the number of jobs and the maximum profit.

Company Tags

Micron Technology Roblox Bloomberg Instacart Morgan Stanley Square Alibaba Airbnb AMD Roche PayPal Siemens Healthineers Western Digital Robinhood Seagate Technology McKinsey & Company Johnson & Johnson eBay GE Healthcare Deloitte Goldman Sachs Zomato Freshworks Riot Games Unity Technologies Google Microsoft Amazon Meta Apple Netflix Adobe