Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort jobs by their deadlines in ascending order.
DSA C#
jobs.Sort((a, b) => a.[1].CompareTo(b.Deadline));Attempts:
3 left
💡 Hint
Common Mistakes
Sorting by Profit instead of Deadline.
Using wrong property names.
Sorting in descending order.
✗ Incorrect
Sorting jobs by their Deadline helps us schedule jobs before their deadlines.
2fill in blank
mediumComplete the code to check if a time slot is free before scheduling a job.
DSA C#
if (slots[[1]] == false) { /* schedule job */ }
Attempts:
3 left
💡 Hint
Common Mistakes
Using job.Deadline as index directly.
Checking wrong array or variable.
Using profit as index.
✗ Incorrect
We check the slot at index i to see if it is free (false) before scheduling.
3fill in blank
hardFix the error in the loop that tries to find a free slot for a job before its deadline.
DSA C#
for (int i = Math.Min(maxDeadline, job.Deadline); i > 0; i[1]) { /* check slot */ }
Attempts:
3 left
💡 Hint
Common Mistakes
Using ++ causes infinite loop or wrong slot checking order.
Using += or -= with wrong values.
Not decrementing i.
✗ Incorrect
We decrement i to check slots from the job's deadline backwards to find a free slot.
4fill in blank
hardFill both blanks to correctly mark a slot as occupied and add the job's profit.
DSA C#
slots[[1]] = true; totalProfit [2]= job.Profit;
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong slot index variable.
Using '-' instead of '+=' for profit.
Marking slot as false instead of true.
✗ Incorrect
Marking slot i as true means it's occupied, and adding job.Profit to totalProfit accumulates profit.
5fill in blank
hardFill all three blanks to create a dictionary of scheduled jobs with their profits, filtering only profitable jobs.
DSA C#
var scheduledJobs = jobs.Where(job => job.Profit [1] 0) .ToDictionary(job => job.[2], job => job.[3]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in filter.
Using wrong properties for dictionary keys or values.
Not filtering profitable jobs.
✗ Incorrect
We filter jobs with Profit > 0, then create a dictionary with job Id as key and Profit as value.
