Skip to content

Practice Single-Threaded CPU

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1834
LeetCode Problem

Single-Threaded CPU

Problem Statement

tasks[i] = [enqueueTime,processingTime] describes a task with original index i. A single CPU waits if no task is available. When idle with tasks available, it chooses the shortest processing time, breaking ties by smallest original index. Once started, a task runs to completion; the next may start immediately. Return the task indices in processing order.

Source: Single-Threaded CPU on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
tasks = [[1,2],[2,4],[3,2],[4,1]]
Output
[0,2,3,1]

# Example 2

Input
tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]
Output
[4,3,2,0,1]

Constraints

tasks.length == n
1 <= n <= 10^5
1 <= enqueueTimei, processingTimei <= 10^9

Related LeetCode Problems

Practice more problems similar to Single-Threaded CPU.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.