Weighted Job Scheduling
You are given 'N' jobs with their start time 'Start', end time 'End' and profit 'Profit'. You need to tell the maximum profit you can obtain by performing these jobs such that no two jobs overlap.
Note:
The start time of one job can be equal to the end time of another.
Input Format:
The first line contains an integer 'T' denoting the number of test cases to be run.
The first line of each test case contains a single integers 'N' denoting the number of jobs.
The second line of each test case contains ‘N’ single space-separated integers denoting the start time of 'N' jobs respectively.
The third line of each test case contains ‘N’ single space-separated integers denoting the end time of 'N' jobs respectively.
The fourth line of each test case contains ‘N’ single space-separated integers denoting the profit of 'N' jobs respectively.
Output Format:
For each test case, the maximum profit is printed.
Print the output of each test case in a separate line.
Follow up :
Can you solve this problem in O(N*log(N)) time complexity?
Constraints:
1 <= T <= 100
1 <= N <= 3000
1 <= Start[i] < End[i] <= 10^9
1 <= Profit[i] <= 10^9
Where 'T' denotes the number of test cases, 'N' denotes the number of jobs respectively, 'Start[i]' and 'End[i]' denotes the start and end time of 'i-th' job, and 'Profit[i]' denotes the profit of 'i-th' job.
CodingNinjas
author
2y
Algorithm:
- Take a DP array of size ‘N’ and initialize all its values with 0.
- DP[0] = 1
- For every index ‘i’ of the Jobs array
- Iterate over the indices for all ‘j’ such that i-1 >= j >= 0, and if the job a...read more
CodingNinjas
author
2y
Brute Force
- The idea is to use recursion to reduce the big problem into several smaller subproblems.
- The idea is to create an array of ‘Jobs’ of size N, where each entry of Jobs will have three elements...read more
CodingNinjas
author
2y
Recursive Memoization
We are solving this problem by solving its subproblems and then combining the solutions of those subproblems. If we analyze carefully, we will see that we are solving the same sub...read more
CodingNinjas
author
2y
Bottom Up DP
This approach relies on the fact that the maximum profit possible up to ith index is independent of the jobs coming after the ith index. Thus, for every index we will store the maximum pro...read more
CodingNinjas
author
2y
Using Binary Search
- An optimization of the previous approach is to use binary search as the jobs are sorted in increasing order of finish time.
- We use binary search to find the latest non conflicting jo...read more
Add answer anonymously...
Top PhonePe Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in PhonePe Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app