Agent Task Dependency Tracker
Learn this problemProblem statement
Process operations against an initially empty task list. Task IDs are consecutive integers starting at 1. Each task has a description and one of these statuses, in increasing order:
BLOCKED < READY_TO_EXECUTE < IN_PROGRESS < SUCCEEDED < FAILED.
["ADD", description, dependencyId...]adds a task. All dependency IDs refer to earlier tasks. Its initial status isREADY_TO_EXECUTEwhen it has no dependencies or every dependency isSUCCEEDED; otherwise it isBLOCKED. Returnid:status.["GET", taskId]returnsid|status|description, orNULLwhen the task does not exist.["SET", taskId, newStatus]changes a task's status only when the ID exists, the current status is not terminal, andnewStatusis strictly higher than the current status. Return lowercasetrueon success andfalseotherwise.["RENDER"]returns the deterministic representation described below.
After a successful SET:
- Every
BLOCKEDtask whose direct dependencies are now allSUCCEEDEDbecomesREADY_TO_EXECUTE. - If a task becomes
FAILED, every currentlyBLOCKEDtask that directly or indirectly depends on it becomesFAILED.
The only transition out of BLOCKED in the operation stream is the automatic readiness or failure transition above; SET is never issued for a currently blocked task.
For RENDER, list tasks in increasing ID order, one per line, as id|status|dependencies|description. Write dependency IDs in increasing order separated by commas, or - when there are none. An empty task list renders as the empty string.
Return one output string for every input operation, in order.
Function
runAgentTodoList(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD","fetch weather"],["ADD","summarize forecast","1"],["GET","2"],["SET","1","IN_PROGRESS"],["SET","1","SUCCEEDED"],["GET","2"],["RENDER"]]return = ["1:READY_TO_EXECUTE","2:BLOCKED","2|BLOCKED|summarize forecast","true","true","2|READY_TO_EXECUTE|summarize forecast","1|SUCCEEDED|-|fetch weather\n2|READY_TO_EXECUTE|1|summarize forecast"]Task 2 starts blocked. When task 1 succeeds, task 2 has no unfinished dependency and becomes ready. Rendering lists both tasks in ID order.
Example 2
operations = [["ADD","root"],["ADD","left","1"],["ADD","right","1"],["ADD","merge","2","3"],["SET","1","FAILED"],["GET","2"],["GET","3"],["GET","4"]]return = ["1:READY_TO_EXECUTE","2:BLOCKED","3:BLOCKED","4:BLOCKED","true","2|FAILED|left","3|FAILED|right","4|FAILED|merge"]Failure travels through both branches of the dependency graph. The shared descendant is processed once and ends in the terminal failed state.
Constraints
1 <= operations.length <= 200000.- There are at most
100000ADDoperations and at most200000total dependency references. - The sum, over every
RENDER, of the number of tasks rendered is at most200000. - Each operation has the exact form shown above.
- Every dependency ID is a unique positive integer naming an earlier task, so the dependency graph is acyclic.
- Descriptions are non-empty ASCII strings containing neither
|nor a newline; their total length is at most1000000. taskIdvalues and dependency IDs are canonical decimal strings without leading zeroes.newStatusis one ofBLOCKED,READY_TO_EXECUTE,IN_PROGRESS,SUCCEEDED, orFAILED.- A
SEToperation is never issued for a task whose current status isBLOCKED.