Tap here to switch tabs
Problem
Submissions

Problem: Maximum Segment Sum After Removals

Maximum Segment Sum After Removals gives an array and an order of removals. After each removal, return the largest sum among all contiguous segments of elements that remain, or zero when none are left.

Statement

You are given two 00 indexed integer arrays nums and removeQueries, both of length n. For each query from 00 to n−1n - 1, the element in nums at the index removeQueries[i] is marked as removed.

A segment is defined as a contiguous subsequence of non removed elements in nums. The sum of a segment is the sum of all elements present in that segment.

You need to process the queries sequentially. After each query, determine the maximum segment sum among all active segments. If no segments remain, the maximum segment sum is 00.

Return an integer array ans of length n, where ans[i] represents the maximum segment sum after applying the ii-th removal query.

Constraints:

  • n ==== nums.length ==== removeQueries.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq removeQueries[i] << n

  • All the values of removeQueries are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Segment Sum After Removals

Maximum Segment Sum After Removals gives an array and an order of removals. After each removal, return the largest sum among all contiguous segments of elements that remain, or zero when none are left.

Statement

You are given two 00 indexed integer arrays nums and removeQueries, both of length n. For each query from 00 to n−1n - 1, the element in nums at the index removeQueries[i] is marked as removed.

A segment is defined as a contiguous subsequence of non removed elements in nums. The sum of a segment is the sum of all elements present in that segment.

You need to process the queries sequentially. After each query, determine the maximum segment sum among all active segments. If no segments remain, the maximum segment sum is 00.

Return an integer array ans of length n, where ans[i] represents the maximum segment sum after applying the ii-th removal query.

Constraints:

  • n ==== nums.length ==== removeQueries.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq removeQueries[i] << n

  • All the values of removeQueries are unique.