Single-Threaded CPU Scheduling
Medium · Heap & Priority Queue · about 25 minutes
Asked at Google, Amazon, Microsoft, Databricks.
Tasks are given as tasks[i] = [enqueueTime, processingTime]. A single-threaded CPU, whenever it is idle and tasks are available, picks the available task with the shortest processing time (ties broken by the smaller index) and runs it to completion. If nothing is available it waits for the next task. Return the order in which the CPU processes the task indices.