
									 Problem
								
								
									 Solution
								
								
									 Submissions
								
								
							Maximum Profit in Job Scheduling
								Certification: Advanced Level
								Accuracy: 100%
								Submissions: 1
								Points: 15
							
							Write a Java program to find the maximum profit you can achieve by scheduling jobs. You have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i]. You need to find the maximum profit you can get if you can only work on one job at a time.
Example 1
- Input: startTime = [1, 2, 3, 3] endTime = [3, 4, 5, 6] profit = [50, 10, 40, 70]
 - Output: 120
 - Explanation: 
The jobs are:
- Job 1: Start at time 1, end at time 3, profit 50
- Job 2: Start at time 2, end at time 4, profit 10
- Job 3: Start at time 3, end at time 5, profit 40
- Job 4: Start at time 3, end at time 6, profit 70
The maximum profit can be achieved by scheduling Job 1 and Job 4. Job 1 starts at time 1 and ends at time 3, with profit 50. Job 4 starts at time 3 and ends at time 6, with profit 70. Total profit = 50 + 70 = 120. 
Example 2
- Input: startTime = [1, 2, 3, 4, 6] endTime = [3, 5, 10, 6, 9] profit = [20, 20, 100, 70, 60]
 - Output: 150
 - Explanation:
The jobs are:
- Job 1: Start at time 1, end at time 3, profit 20
- Job 2: Start at time 2, end at time 5, profit 20
- Job 3: Start at time 3, end at time 10, profit 100
- Job 4: Start at time 4, end at time 6, profit 70
- Job 5: Start at time 6, end at time 9, profit 60
The maximum profit can be achieved by scheduling Job 1 and Job 4 and Job 5. Job 1 starts at time 1 and ends at time 3, with profit 20. Job 4 starts at time 4 and ends at time 6, with profit 70. Job 5 starts at time 6 and ends at time 9, with profit 60. Total profit = 20 + 70 + 60 = 150. 
Constraints
- 1 ≤ startTime.length == endTime.length == profit.length ≤ 5 * 10^4
 - 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 the jobs based on their end times
 - Use dynamic programming to find the maximum profit
 - For each job, you have two choices: either take the job or don't take it
 - If you take a job, you can't take jobs that overlap with it
 - Use binary search to find the latest job that finishes before the current job starts
 - Build a bottom-up DP array where dp[i] represents the maximum profit up to the ith job
 - For each job, update dp[i] = max(profit[i] + dp[j], dp[i-1]), where j is the latest non-overlapping job