← 返回 scale.ai 的题目列表Task Scheduler with Dependencies and Deadline Updates
类型:online_judge
Problem: Task Scheduler with Dependencies + Deadline Updates (Part 3)
Extend Part 2 by adding:
updateDeadline(taskId, newDeadline)
You must implement:
addTasks(tasks)
consumeTask()
updateDeadline(taskId, newDeadline)
Additional rules
You may update the deadline only if the task has not been consumed.
Future consumeTask() calls must respect the latest deadlines.
Using a heap, you can apply lazy updates:
On updateDeadline, push (newDeadline, taskId) into the heap.
On consumeTask, when popping, verify the popped deadline equals the task’s current deadline; otherwise discard and continue.
If taskId does not exist or has already been consumed, updateDeadline is a no-op (or returns failure; clarify in interview).
Sample tests
Update changes priority: add (1,5),(2,3); update 1->1; consumes => 1,2
Update blocked task: add 1, and 2 depends on 1; update 2 deadline smaller; consumes => 1,2
Updating consumed task has no effect
Multiple updates: latest value wins
Updating when nothing consumable should not crash
Example
Input
addTasks: [(1,5,[]),(2,3,[])]
updateDeadline(1,1)
consumeTask(); consumeTask()
Output
1 2