Skip to content

Assessment  #72

Open
Open
@ghost

Description

import java.util.Arrays;
import java.util.Comparator;

public class JobSelection {
public static int[] findJobs(int[][] jobs) {
int n = jobs.length;
// Sort the jobs in decreasing order of their profit values
Arrays.sort(jobs, new Comparator<int[]>() {
public int compare(int[] a, int[] b) {
return b[2] - a[2];
}
});
// Initialize the end time of the previously selected job as -1
int end_time = -1;
// Initialize the count of selected jobs as 0
int selected_jobs = 0;
// Initialize the total profit as 0
int total_profit = 0;
for (int[] job : jobs) {
int start_time = job[0];
int end_time1 = job[1];
int profit = job[2];
// Check if it's feasible to perform the job
if (start_time >= end_time) {
selected_jobs++;
total_profit += profit;
end_time = end_time;
}
}
return new int[] {n - selected_jobs, total_profit};
}
public static void main(String[] args) {
int[][] jobs = {{900, 910, 20}, {910, 920, 30}, {930, 940, 10}, {950, 1000, 50}};
int[] result = findJobs(jobs);
System.out.println("Number of jobs left: " + result[0]);
System.out.println("Total earnings of other employees: " + result[1]);
}
}
https://user-images.githubusercontent.com/122772426/212658152-b4105710-4ede-42a5-94b1-b88ca5ce57b5.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions