← 返回 amazon 的题目列表Priority Job Scheduler with Invocation-Based Cooldown
类型:online_judge
Implement a job scheduler. Each job has a unique jobId and a priority; higher priority jobs should be returned first, with FIFO ordering among equal priorities.
Implement:
addJob(jobId, priority, delay=0)
getJob()
After a job is successfully returned by getJob(), it cannot be returned again until at least delay subsequent invocations of getJob() have occurred. Calls that return no job also count as invocations.
Re-adding an existing jobId may be treated as replacing its priority and delay and making it immediately eligible again.
For the CLI, input is JSON in the form {"commands":[["add","A",5,2],["get"],...]}. Print a JSON array containing the result of every get; use null for no available job.
Constraints: up to 2 * 10^5 commands; target approximately O(log n) time per API call.
Example
Input
{"commands":[["add","A",5,0],["add","B",9,0],["get"],["get"]]}
Output
["B","A"]