Job Sequencing Problem
You are given a N x 2 2-D array 'Jobs' of 'N' jobs where Jobs[i][0] denote the deadline of i-th job and Jobs[i][1] denotes the profit associated with i-th job.
You will make a certain profit if you complete the job within the deadline associated with it. Each job takes 1 unit of time to be completed, and you can schedule only one job at a particular time.
Your task is to find out the maximum profit that you can make.
Note :
If a particular job has a deadline 'x', it means that it needs to be completed at any time interval before 'x'.
For Example :
If jobs is -
[ 2 40 ]
[ 2 20 ]
[1 10 ]
So, there are a total of 3 jobs. The first job has a deadline of 2, and the profit associated with it is 40. The second job has a deadline of 2, and the profit is 20. Similarly, the third job has a deadline of 1, and the profit is 10.
So, it’s optimal to complete the first and second jobs to earn a profit of 60. One of the jobs can be completed in the first minute, and the second job can be completed in the next minute. So, the total profit = 40 + 20 = 60, and the number of completed jobs is 2. Since the third job can’t be completed within the deadline, so we do not earn any profit.
Follow Up :
Can you solve this in (N*log(N)) time complexity?
Input Format :
The first line contains an integer 'T', which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first line of each test case contains a single integer N, denoting the number of elements of the array “jobs”.
The second line of each test case contains 'N' space-separated integers denoting the deadline assigned to each job.
The third line of each test case contains 'N' space-separated integers denoting the profit associated with each job.
Output Format :
For each test case, print the maximum profit that can be earned.
Output for each test case will be printed in a separate line.
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 100
1 <= N <= 5000
1 <= jobs[i][0] <= 3000
1 <= jobs[i][1] <= 10^5
Time limit: 1 sec
Be the first one to answer
Add answer anonymously...
Top Ola Cabs SDE-2 interview questions & answers
Popular interview questions of SDE-2
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