VOOZH about

URL: https://www.geeksforgeeks.org/dsa/weighted-job-scheduling-log-n-time/

⇱ Weighted Job Scheduling Memoization Solution in O(n Log n) time - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Weighted Job Scheduling Memoization Solution in O(n Log n) time

Last Updated : 6 Oct, 2025

Given n jobs where every job has the following properties:

  • Start Time
  • Finish Time
  • Profit or Value Associated

The task is to find the maximum profit in scheduling jobs such that no two jobs overlap.

Examples: 

Input: jobs[][] = [[1, 2, 50],
[3, 5, 20],
[6, 19, 100],
[2, 100, 200]]
Output: 250
Explanation:

  • Job (1, 2, 50) can be chosen first.
  • Job (3, 5, 20) can be skipped because it's not the most profitable choice compared to Job (6, 19, 100).
  • Job (6, 19, 100) can be selected next.
  • Job (2, 100, 200) is skipped as it overlaps with Job (1, 2, 50).

Thus, the selected jobs are Job 1 and Job 3, resulting in a total profit of 50 + 200 = 250.

Input: jobs[][] = [[1, 3, 60],
[2, 5, 50],
[4, 6, 70],
[5, 7, 30]]
Output: 130
Explanation:

  • Job (1, 3, 60) is selected.
  • Job (2, 5, 50) is skipped as it overlaps with Job (1, 3, 60).
  • Job (4, 6, 70) is selected.
  • Job (5, 7, 30) is skipped as it overlaps with Job (4, 6, 70).

The total maximum profit here is 60 (Job 1) + 70 (Job 3) = 130.

Approach:

We have discussed recursive and Dynamic Programming-based approaches in the Weighted Job Scheduling.

The problem of finding the maximum profit in scheduling non-overlapping jobs can be solved using dynamic programming. The approach begins by sorting the jobs in ascending order based on their start times, which helps efficiently identify the next non-overlapping job using binary search. The recursive solution explores two options for each job: either include it in the schedule, adding its profit and recursively calculating the profit of the next compatible job, or exclude it and move on to the next job. Memoization is used to store previously calculated results for subproblems to avoid redundant calculations. The function returns the maximum profit by selecting the optimal combination of jobs, ensuring that no two jobs overlap.


Output
250

Time Complexity: O(nlogn)
Auxilairy Space : O(n)

Comment
Article Tags: