Select Least Resource Tasks
Updated
Problem statement
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[]) → intExamples
Example 1
resourceConsumption = [4, 3, 2, 1]return = 4The 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 = 68First 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 <= 20001 <= resourceConsumption[i] <= 10^5
More Amazon Online Assessment questions
- Get Smallest Base SegmentOA · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Nov 2026
- Minimum Merge ConflictsOA · Seen Nov 2026
- Shopping Cart BillingOA · Seen Nov 2026
Amazon interview experiences
- Amazon SWE OA with AI Coding: 1 Experience
- Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
- Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
- Amazon BIE Intern SQL and Interview Questions: 17 Experiences
- Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
- Amazon SDE II (L5) Interview Questions: 5 Experiences