Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Dec 12, 2023
1 parent a61babc commit 7305b1f
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function optimalFreelancing(jobs) {
let profit = 0;
let day = 7;
let completedJobs = new WeakSet();

while (day > 0) {
let bestJob;

for (let job of jobs) {
if (
job.deadline >= day &&
job.payment > (bestJob?.payment || 0) &&
!completedJobs.has(job)
) {
bestJob = job;
}
}

day--;

if (bestJob) {
completedJobs.add(bestJob);
profit += bestJob.payment;
}
}

return profit;
}

0 comments on commit 7305b1f

Please sign in to comment.