FastPrepMinimized Total Idle Time
Problems/Minimized Total Idle Time

Minimized Total Idle Time

Flipkart logoFlipkartFULLTIMEOA

Updated Jul 2026

QuestionFunctionExamplesConstraints

Problem 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[]) → long

Examples

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.

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

More Flipkart interview questions

  • K-th Element of Two Sorted ArraysONSITE INTERVIEW · Seen Oct 2026
  • Zigzag Level-Order TraversalONSITE INTERVIEW · Seen Oct 2026
See Flipkart hiring insights
Saved
class Solution {
    public long minimizedTotalIdleTime(int[] processingTimes) {
      // write your code here
    }
}
Checking account…