Timed Task Management
Problem statement
Implement a finite task-management operation stream. Each task has a unique string ID, integer creation time, inclusive start time, exclusive end time, integer priority, and completion state. A task takes one integer time unit to run.
["ADD", id, created, start, end, priority]: add the task and return"true", or"false"for a duplicate ID.["FILTER", field, value]: list unfinished tasks whoseCREATED,START,END, orPRIORITYfield equals value.["RANGE", left, right]: list unfinished tasks whose start time is in[left,right).["RUN", timestamp]: complete one unfinished task withstart <= timestamp < end. Choose greatest priority, then earliest creation time, then lexicographically smallest ID. Return its ID orNONE.["FINISHED", id]: return whether the task exists and is finished.["CAN_FINISH", left, right]: without mutating state, return whether every unfinished task whose window intersects[left,right)can receive a distinct integer unit slot within the intersection of its own window and that range.
FILTER and RANGE use the same priority, creation-time, and ID ordering and join IDs with commas.
Function
manageTimedTasks(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD","a","0","1","4","3"],["ADD","b","1","1","3","5"],["FILTER","PRIORITY","5"],["RUN","1"],["FINISHED","b"],["CAN_FINISH","1","4"]]return = ["true","true","b","b","true","true"]b has greater priority and runs first. The remaining unit task a fits before time 4.
Example 2
operations = [["ADD","a","0","0","1","1"],["ADD","b","0","0","1","2"],["RANGE","0","2"],["CAN_FINISH","0","1"],["RUN","2"]]return = ["true","true","b,a","false","NONE"]Both tasks require the only slot [0,1), so they cannot both finish. Neither is eligible at time 2.
Constraints
1 <= operations.length <= 5000.- IDs are nonempty and contain no commas.
0 <= created <= start < end <= 10^9.- At most 500 unfinished tasks participate in one CAN_FINISH query.