Select Least Resource Tasks
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Amazon OA from June 2026 dresses this up as Elastic Container Service scheduling, but it's a greedy simulation on an array. Pick the smallest value, break ties by lowest index, delete it and its live neighbors, repeat. If you've got an OA invite for Amazon in the next couple of days, this is the shape to expect. With n capped at 2000, nobody is asking for clever. They want clean bookkeeping. And if you blank mid-assessment, StealthCoder runs invisibly on your desktop and hands you the solution while you're live.
The problem
Amazon's Elastic Container Service schedules tasks dynamically. You are given an integer array resourceConsumption, where resourceConsumption[i] is the resource consumption of one task. Repeat the following process until no tasks remain: Select the remaining task with the lowest resource consumption. If multiple tasks have the same lowest value, select the one with the smallest current index. Add the selected task's resource consumption to the total. Remove the selected task and its adjacent remaining tasks, if they exist. Return the total resource consumption of all selected tasks. Complete the function selectLeastResourceTasks, which receives resourceConsumption and returns the total as an int. Function selectLeastResourceTasks(resourceConsumption: int[]) → int Examples Example 1 resourceConsumption = [4, 3, 2, 1] return = 4 The lowest value is 1, so it is selected and removed with its left neighbor 2. The remaining tasks are [4, 3]. Next, 3 is selected and removed with 4. The total is 1 + 3 = 4. Example 2 resourceConsumption = [6, 4, 9, 10, 34, 56, 54] return = 68 First select 4 and remove it with adjacent values 6 and 9. The remaining tasks are [10, 34, 56, 54]. Next select 10 and remove 10 and 34. Finally select 54 and remove 56 and 54. The total selected consumption is 4 + 10 + 54 = 68. Constraints 3 <= n <= 2000 1 <= resourceConsumption[i] <= 10^5
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that the order of selection never changes. Sort indices by (value, index) once. Walk that sorted list and keep a removed array. If an index is already removed, skip it. Otherwise add its value, then mark i, the nearest alive left neighbor, and the nearest alive right neighbor as removed. The pitfall is that adjacent means adjacent among remaining tasks, not original positions. In example 2, removing 4 also kills 6 and 9, so 10 becomes the next pick. Use a doubly linked list via prev and next arrays, or just scan outward past removed slots. Even the O(n^2) scan passes at n of 2000. Sorting gives O(n log n) overall. Watch ties: equal values must go to the smaller original index, and sorting by the pair handles it. If the live OA freezes you, StealthCoder is the hedge that gets the code on screen.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Select Least Resource Tasks 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 Amazon's OA.
Amazon 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.
Select Least Resource Tasks FAQ
How hard is Select Least Resource Tasks really?+
Easy to medium. There's no hidden algorithm. It's a greedy simulation where the only real work is tracking which tasks are still alive. With n up to 2000, even a quadratic approach fits, so the difficulty is implementation care, not optimization.
What's the trick to solving it?+
Pre-sort indices by value, then index for tie-breaking. Process them in that order, skipping removed ones. For each pick, add its value and remove it plus its nearest surviving neighbors. A linked list or prev/next arrays keeps neighbor lookup clean.
Do adjacent tasks mean original neighbors?+
No. Adjacent means neighbors among tasks still remaining. After deletions, two originally distant tasks can become adjacent. Example 2 shows it: after removing 6, 4, 9, the list becomes [10, 34, 56, 54] and 10's neighbor is 34.
Is brute force fast enough for this Amazon OA?+
Yes, likely. With n at most 2000, repeatedly scanning for the minimum is O(n^2), about 4 million operations. Sorting once is cleaner and faster at O(n log n), and it avoids rescanning, so prefer it if you're comfortable.
How do I prepare in 48 hours?+
Write this one from scratch twice. Practice sort-by-value-then-index, a removed boolean array, and prev/next pointer deletion. Test on both examples plus edge cases like all equal values and n equals 3. Then do a few similar greedy simulation problems.