← 返回 roblox 的题目列表Single-Threaded CPU (LeetCode 1834)
类型:qbank
Simulate a single-threaded CPU that picks available tasks by shortest processing time, then original index.
Examples
Example 1:
Input: tasks = [[1,2],[2,4],[3,2],[4,1]]
Output: [0,2,3,1]
Explanation:
CPU starts at t=1 with task 0 (length 2). At t=3, tasks 1 and 2 are ready — task 2 wins (length 2 vs 4). At t=5 only task 3 remains and runs (length 1). At t=6 task 1 runs (length 4).
Example 2:
Input: tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]
Output: [4,3,2,0,1]
Explanation:
All tasks arrive at t=7; the CPU drains them by shortest processing time, breaking ties by index.
Constraints
1 <= tasks.length <= 10^5
1 <= enqueueTime_i, processingTime_i <= 10^9