Job Scheduling Problem

You are provided with a list of jobs, where each job has a specific deadline and profit. The goal is to schedule these jobs such that the total profit is maximized. Each job requires exactly one unit of time and only one job can be scheduled at any given time.

Explanation:

Schedule the jobs by maximizing the total profit, ensuring that each job is completed before its respective deadline. Jobs can only be scheduled at integer times starting from 1.

Input:

The first line of the input contains an integer ‘T’ representing the number of test cases. Each test case begins with an integer ‘N’ denoting the number of jobs. The next ‘N’ lines contain two space-separated integers: deadline[i] and profit[i] for the i-th job.

Output:

For each test case, output the maximum profit achievable by scheduling the jobs optimally. Each result should be printed on a new line.

Example:

Jobs: A (Profit: 20, Deadline: 1), B (Profit: 30, Deadline: 2), C (Profit: 40, Deadline: 2)
Scheduled Order: C at t=1, B at t=2
Total Profit: 70

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 10^3
  • 1 <= deadline[i] <= N
  • 1 <= profit[i] <= 10^9
  • Time Limit: 1 sec

Note:

You do not need to print anything; it has already been implemented. Focus on completing the function provided.

AnswerBot
4mo

The goal is to schedule jobs to maximize profit while meeting deadlines. Each job takes one unit of time and only one job can be scheduled at a time.

  • Sort the jobs in decreasing order of profit

  • Iterate ...read more

Help your peers!
Select
Add answer anonymously...

Atlassian Software Developer interview questions & answers

A Software Developer was asked Q. Implement the snake game.
A Software Developer was asked Q. How would you find the top k collections?
A Software Developer was asked Q. Find total size

Popular interview questions of Software Developer

A Software Developer was asked Q1. Implement the snake game.
A Software Developer was asked Q2. Find total size
A Software Developer was asked Q3. Design File System : You have given file size and collection in input 1 : get to...read more
Atlassian Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits