Minimum Processing Time — LeetCode 2895 Python Solution
MediumGreedyArraySorting
- Problem
- #2895
- Pattern
- Greedy
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You have a certain number of processors, each having 4 cores. The number of tasks to be executed is four times the number of processors.
Python solution
Python
class Solution:
def minProcessingTime(self, processorTime: List[int], tasks: List[int]) -> int:
processorTime.sort()
tasks.sort()
ans = 0
i = len(tasks) - 1
for t in processorTime:
ans = max(ans, t + tasks[i])
i -= 4
return ansComplexity
| Measure | Complexity |
|---|---|
| Time | O(n \times \log n) |
| Space | O(\log n) auxiliary |
Pattern: Greedy
Take the locally best option every time — when you can prove that never costs you later. LeetCode 2895. Minimum Processing Time is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Greedy.
The greedy guide has the Python template for the pattern and the 346 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2895. Minimum Processing Time?
- LeetCode 2895. Minimum Processing Time is rated Medium on LeetCode.
- What is the time complexity of LeetCode 2895. Minimum Processing Time?
- The Python solution on this page runs in O(n \times \log n).
- What is the space complexity of LeetCode 2895. Minimum Processing Time?
- The Python solution on this page uses O(\log n) auxiliary space.
- What topics does LeetCode 2895. Minimum Processing Time cover?
- LeetCode 2895. Minimum Processing Time is tagged Greedy, Array and Sorting on LeetCode.