Asked inOla Cabs,SDE-2

Job Sequencing Problem Statement

You are provided with a N x 2 2-D array called Jobs consisting of N jobs. In this array, Jobs[i][0] represents the deadline of the i-th job, while Jobs[i][1] indicates the profit linked with the i-th job.

Your objective is to determine the maximum profit that can be attained by scheduling jobs such that each job is completed within its respective deadline. Note that every job requires one unit of time to complete, and only one job can be scheduled at a particular time.

Example:

Input:
jobs = [[2, 40], [2, 20], [1, 10]]
Output:
60
Explanation:

In this example, it's optimal to complete the first and second jobs to achieve a profit of 60. The first job can be completed in the first unit of time and the second job in the second unit. Thus, the total profit is 40 + 20 = 60. The third job cannot be completed within its deadline, thus no profit is earned from it.

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 5000
  • 1 ≤ jobs[i][0] ≤ 3000
  • 1 ≤ jobs[i][1] ≤ 105
  • Time limit: 1 sec
Note:

If a job has a deadline 'x', it must be completed at any time before 'x'. You only need to implement the function, without handling input and output, which is already managed.

Be the first one to answer
Add answer anonymously...
Ola Cabs SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter