Problem
Minimized Total Idle Time
Learn this problemProblem statement
You are given an array processingTimes, where each element is the processing time of one task.
You may process the tasks in any order. After each processed task, define the current idle time as:
maximum processing time seen so far - minimum processing time seen so far
The total idle time is the sum of the current idle time after every task is processed.
Return the minimum possible total idle time over all processing orders.
Function
minimizedTotalIdleTime(processingTimes: int[]) → longExamples
Example 1
processingTimes = [1,2,2,2,3,3]return = 4One optimal order is [2,2,2,3,3,1]. The idle times after each task are 0,0,0,1,1,2, whose sum is 4.
Example 2
processingTimes = [4,1,7]return = 9Any optimal order has range contributions 3 and 6 after the first task, for total 9.
Constraints
processingTimes.length >= 1