Skip to main content
LeetCode 1834, Medium. Topics: Array, Sorting, Heap (Priority Queue). View on LeetCode. Generate this problem as a practice environment: tested reference solution, 15 parametrized pytest cases, and a playground notebook:

Problem

You are given n tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTime_i, processingTime_i] means that the i^th task will be available to process at enqueueTime_i and will take processingTime_i to finish processing. You have a single-threaded CPU that can process at most one task at a time and will act in the following way:
  • If the CPU is idle and there are no available tasks to process, the CPU remains idle.
  • If the CPU is idle and there are available tasks, the CPU will choose the one with the shortest processing time. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.
  • Once a task is started, the CPU will process the entire task without stopping.
  • The CPU can finish a task then start a new one instantly.
Return the order in which the CPU will process the tasks.

Examples

Constraints

  • tasks.length == n
  • 1 <= n <= 10^5
  • 1 <= enqueueTime_i, processingTime_i <= 10^9

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode 250, NeetCode All.
Last modified on August 25, 2026