Problem
Minimized Total Idle Time
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.
Examples
01 · Example 1
processingTimes = [1,2,2,2,3,3] return = 4
One 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.
02 · Example 2
processingTimes = [4,1,7] return = 9
Any optimal order has range contributions 3 and 6 after the first task, for total 9.
Constraints
processingTimes.length >= 1
public long minimizedTotalIdleTime(int[] processingTimes) {
// write your code here
}processingTimes[1,2,2,2,3,3]
expected4
sign in to submit