Description
Given an array and removal order, return the maximum segment sum after each removal. A segment is a contiguous subarray of remaining elements.
Examples
Input:
nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1]Output:
[14,7,2,2,0]Explanation:
Max after each removal.
Input:
nums = [1], removeQueries = [1]Output:
[1]Explanation:
Edge case with a single-element array.
Input:
nums = [3,1,4,2], removeQueries = [2,1,3,0]Output:
[10,8,3,0]Explanation:
After each removal, the maximum segment sum decreases: 4, 3, 3, 0 as elements are removed one by one.
Constraints
- •
1 ≤ nums.length ≤ 10⁵