0
0
DSA Typescriptprogramming~10 mins

Job Scheduling with Deadlines in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to sort jobs by their deadlines in ascending order.

DSA Typescript
jobs.sort((a, b) => a.deadline [1] b.deadline);
Drag options to blanks, or click blank then click option'
A-
B<
C+
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using comparison operators like '<' or '>' directly inside sort callback.
Returning boolean instead of number in sort function.
2fill in blank
medium

Complete the code to find the maximum deadline among all jobs.

DSA Typescript
const maxDeadline = Math.max(...jobs.map(job => job.[1]));
Drag options to blanks, or click blank then click option'
Aid
Bprofit
Cdeadline
Dduration
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'profit' or other properties instead of 'deadline'.
Not using spread operator with Math.max.
3fill in blank
hard

Fix the error in the code that schedules jobs to maximize profit without missing deadlines.

DSA Typescript
for (let i = 0; i < jobs.length; i++) {
  let j = Math.min(maxDeadline, jobs[i].deadline) - 1;
  while (j >= 0 && slot[j] [1] true) {
    j--;
  }
  if (j >= 0) {
    slot[j] = true;
    result[j] = jobs[i];
  }
}
Drag options to blanks, or click blank then click option'
A!=
B==
C===
D!==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' which would check for false slots incorrectly.
Using assignment '=' instead of comparison.
4fill in blank
hard

Fill both blanks to complete the function that returns the scheduled jobs in order of their slots.

DSA Typescript
function getScheduledJobs(result: (Job | null)[]): Job[] {
  return result.filter(job => job [1] null).[2]((jobA, jobB) => jobA.deadline - jobB.deadline);
}
Drag options to blanks, or click blank then click option'
A!==
Bsort
C==
Dmap
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!==' in filter.
Using 'map' instead of 'sort' after filtering.
5fill in blank
hard

Fill all three blanks to complete the job scheduling function that returns the maximum profit and scheduled jobs.

DSA Typescript
function scheduleJobs(jobs: Job[]): { maxProfit: number; scheduledJobs: Job[] } {
  jobs.sort((a, b) => b.[1] - a.[2]);
  const maxDeadline = Math.max(...jobs.map(job => job.[3]));
  const slot: boolean[] = Array(maxDeadline).fill(false);
  const result: (Job | null)[] = Array(maxDeadline).fill(null);
  let maxProfit = 0;
  for (const job of jobs) {
    let j = Math.min(maxDeadline, job.deadline) - 1;
    while (j >= 0 && slot[j]) { j--; }
    if (j >= 0) {
      slot[j] = true;
      result[j] = job;
      maxProfit += job.profit;
    }
  }
  return { maxProfit, scheduledJobs: result.filter(job => job !== null) as Job[] };
}
Drag options to blanks, or click blank then click option'
Aprofit
Cdeadline
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Sorting by deadline instead of profit.
Using wrong properties in sort or max calculation.