Reported December 2025
Flipkartdynamic programming

Minimized Total Idle Time

Reported by candidates from Flipkart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Flipkart OA. Under 2s to a working solution.
Founder's read

Trying every processing order is n! work, and the only stated constraint is that the array has at least one element, so assume n can be big. That's the trap in Flipkart's Minimized Total Idle Time, reported in December 2025. The task sounds like scheduling, but it's really about nested ranges. You add tasks one at a time, and after each one you pay max minus min of everything seen so far. Sort first, then think in windows. If you've got the OA in a day or two, this one is solvable once you see the structure. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the idea below is short enough to carry in your head.

The problem

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

Reported by candidates. Source: FastPrep

Pattern and pitfall

Order only matters through which set you've seen after each step, and the cost depends only on that set's min and max. Sort the array. Any prefix set that's optimal is a contiguous window of the sorted array, and each step grows the window by one element on the left or the right. So define dp[l][r] as the minimum cost to have processed exactly the window l..r. Then dp[l][r] = (a[r] - a[l]) + min(dp[l+1][r], dp[l][r-1]), with single elements costing 0. Check example 2: sorted 1,4,7 gives 0, then 3, then 6, total 9. The common pitfall is a greedy that always takes the nearest value, which can fail on ties and gaps. Use a long for the sum, since ranges add up fast. If the live OA hits you with a huge n and you freeze, StealthCoder can supply the full solution in real time, but know the recurrence first.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Minimized Total Idle Time cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder
⏵ The honest play

You've seen the question. Make sure you actually pass Flipkart's OA.

Flipkart reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimized Total Idle Time FAQ

What's the trick in Minimized Total Idle Time?+

Sort the array, then realize every prefix of tasks is a contiguous window in sorted order. Each step extends the window left or right. The cost after a step is just window max minus window min. That turns an n! search into an interval DP over sorted positions.

Why can't I just brute force the orderings?+

There are n! orderings and the problem states no small upper bound on length. Even modest inputs blow up. Sorting plus interval DP replaces permutations with O(n^2) states, which is the whole point of the question as reported by Flipkart candidates in December 2025.

What does the recurrence look like?+

After sorting into a, set dp[i][i] = 0. For l < r, dp[l][r] = (a[r] - a[l]) + min(dp[l+1][r], dp[l][r-1]). The answer is the minimum over all starting points, which equals dp[0][n-1] when you build the window outward in reverse, removing from the ends.

What return type and edge cases should I watch?+

The function returns a long, so use 64-bit sums. A single-element array returns 0. Duplicates are fine and actually help, since equal values add zero range. Check example 1 by hand: sorted 1,2,2,2,3,3 should give 4.

How do I prepare for this in 48 hours?+

Practice two things: sorting to expose structure, and interval DP with dp[l][r] built from smaller windows. Hand-trace both examples until 4 and 9 come out. Write the recurrence once from memory, then code it. That's enough for this question.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Flipkart.

OA at Flipkart?
Invisible during screen share
Get it