Company: Uber_all
Difficulty: medium
Maximize the Power Problem Description Given an array arr of non-negative integers and an array power of k integers where k is an even number, perform the following operations: Select two integers i and j from the indices of the current power array. If power[i] ≤ power[j] , add the sum of the subarray arr[power[i]...power[j]] to the total power. If power[i] > power[j] , add the sum of the subarray arr[power[j]...power[i]] to the total power. Delete the elements at indices i and j from power , reducing its length by 2 for the next operation. Starting with 0 initial power, maximize the final power after exactly k/2 operations. Return the maximum power modulo (10 9 + 7). Note: Subarray arr[i...j] denotes the elements arr[i], arr[i+1], ..., arr[j] . Examples Example 1: Input: arr = [3, 5, 6, 0, 7], power = [3, 1, 0, 2] Output: 25 Explanation: The size of power, k=4 , so we perform k/2 = 2 operations. One optimal approach is shown: Operation 1: Choose elements 3 and 0 from power (thes