Company: Amazon_26july
Difficulty: medium
In Amazon's Elastic Container Service (ECS), tasks are scheduled and managed dynamically. You are given an array resourceConsumption of n integers, where each element represents the resource consumption of a specific task in the system. To optimise system load and clear tasks efficiently, the following termination process is applied repeatedly until no tasks remain: In each iteration, select the task with the lowest resource consumption. Remove that task and its adjacent tasks (its immediate left and right neighbours, if they exist) from the array. The selected task in an iteration is the one with the minimum resource usage at that moment. Your job is to compute the total resource consumption of all the selected tasks — that is, the sum of the minimum values chosen across every iteration. Note: If more than one task shares the same lowest resource consumption, select the one with the smallest index. Adjacency is always determined by the array as it currently stands (after previous