Maximize Sum of Processed Times
Reported by candidates from Agoda's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Agoda asked this in September 2024, and it's a scheduling optimization problem that looks simple until you realize the order matters. You're maximizing the sum of processed times, which means you need to figure out which order to process items to get the biggest total. The trap is thinking greedy works here. It doesn't always. StealthCoder can spot the pattern in seconds if you blank on the approach during the live OA.
Pattern and pitfall
This is a classic greedy + math problem disguised as optimization. The key insight: if you process items in a certain order, each item contributes to the sum based on when it finishes. If item i takes time t_i and finishes at position p, it contributes t_i * (n - p + 1) or similar to the total. Sorting by processing time (ascending or descending) and calculating the cumulative effect is the move. The common pitfall is trying dynamic programming when a single sort pass solves it. The algorithmic shape is greedy with a math twist. If you're unsure mid-OA, StealthCoder runs silently and gives you the sorting strategy to test.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Maximize Sum of Processed Times 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 would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Agoda's OA.
Agoda reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximize Sum of Processed Times FAQ
Is this a DP problem or greedy?+
Greedy. Sort the items by processing time and calculate the cumulative contribution. DP is overkill and wastes time. The optimal order is deterministic once you see the math.
What's the trick with processed times?+
Each item's contribution depends on its position in the sequence. If you process items in order, later items don't contribute to earlier items' finish times. Sort ascending and multiply each by its remaining weight in the sum.
Can I solve this without sorting?+
No. Sorting is the foundational move. After sort, the cumulative sum is linear. Without sorting, you're guessing permutations.
How do I handle ties in processing time?+
Ties don't matter for the optimal order. Any permutation of tied items gives the same total. Pick an arbitrary tie-breaker or leave them as-is.
Is this still asked at Agoda after September 2024?+
Hard to say, but scheduling and greedy optimization are core to Agoda's backend. This pattern recycles. Know how to sort and calculate cumulative sums fast.