Tap here to switch tabs
Problem
Submissions

Problem: Single-Threaded CPU

med
30 min
Try to solve the Single-Threaded CPU problem.

Statement

You are given a list tasks of length n, where each tasks[i] = [enqueueTime_i, processingTime_i] describes a single task. Task i becomes available to run at time enqueueTime_i and requires processingTime_i units of CPU time to complete.

A single threaded CPU can run at most one task at a time. When the CPU becomes idle, it must choose one available task to execute using the following rules:

  1. Select the available task with the smallest processingTime_i.

  2. If multiple available tasks have the same processingTime_i, select the one with the smallest index i.

Once the CPU starts a task, it runs it to completion without preemption. If no tasks are available, the CPU remains idle until the next task becomes available.

Return an array containing the indices of the tasks in the exact order they are processed by the CPU.

Constraints:

  • tasks.length == n

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq enqueueTime_i, processingTime_i ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Single-Threaded CPU

med
30 min
Try to solve the Single-Threaded CPU problem.

Statement

You are given a list tasks of length n, where each tasks[i] = [enqueueTime_i, processingTime_i] describes a single task. Task i becomes available to run at time enqueueTime_i and requires processingTime_i units of CPU time to complete.

A single threaded CPU can run at most one task at a time. When the CPU becomes idle, it must choose one available task to execute using the following rules:

  1. Select the available task with the smallest processingTime_i.

  2. If multiple available tasks have the same processingTime_i, select the one with the smallest index i.

Once the CPU starts a task, it runs it to completion without preemption. If no tasks are available, the CPU remains idle until the next task becomes available.

Return an array containing the indices of the tasks in the exact order they are processed by the CPU.

Constraints:

  • tasks.length == n

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq enqueueTime_i, processingTime_i ≤109\leq 10^9