
Problem
Solution
Submissions
Maximum Profit in Job Scheduling
Certification: Advanced Level
Accuracy: 0%
Submissions: 0
Points: 20
Write a C program to find the maximum profit that can be obtained by scheduling non-overlapping jobs. Each job has a start time, end time, and profit value. You need to select a subset of jobs such that no two jobs overlap and the total profit is maximized. Two jobs overlap if one starts before the other ends.
Example 1
- Input: jobs = [[1,3,50],[2,4,10],[3,5,40],[4,6,70]]
- Output: 120
- Explanation:
- We can select jobs [1,3,50] and [4,6,70].
- These jobs don't overlap (job 1 ends at time 3, job 2 starts at time 4).
- Total profit = 50 + 70 = 120.
- This is the maximum possible profit.
- We can select jobs [1,3,50] and [4,6,70].
Example 2
- Input: jobs = [[1,2,50],[3,4,10],[2,5,20]]
- Output: 60
- Explanation:
- We can select jobs [1,2,50] and [3,4,10].
- These jobs don't overlap.
- Total profit = 50 + 10 = 60.
- We can select jobs [1,2,50] and [3,4,10].
Constraints
- 1 ≤ jobs.length ≤ 50000
- 1 ≤ startTime[i] < endTime[i] ≤ 10^9
- 1 ≤ profit[i] ≤ 10^4
- Time Complexity: O(n log n)
- Space Complexity: O(n)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Sort jobs by their end times to process them in chronological order
- Use dynamic programming where dp[i] represents maximum profit using jobs 0 to i
- For each job, find the latest non-overlapping job using binary search
- Choose maximum between including current job or excluding it
- Use memoization to avoid recalculating subproblems