Usable Water with Contaminated Pillars
Problem statement
You are given bar heights and a same-length binary contamination array. Rainwater is trapped by the bars under the usual one-dimensional rules.
Water directly above index i is unusable when contaminated[i] == 1; do not include those units in the result. Return the total usable trapped water above clean positions.
Function
usableTrappedWater(height: int[], contaminated: int[]) → longExamples
Example 1
height = [0,1,0,2,1,0,1,3,2,1,2,1]contaminated = [0,0,0,0,0,1,0,0,0,0,0,0]return = 4The standard total is 6, but the two units above contaminated index 5 are excluded.
Example 2
height = [4,2,0,3,2,5]contaminated = [0,0,1,0,0,0]return = 5Four of the standard nine units lie above the contaminated index and are excluded.
Constraints
1 <= height.length == contaminated.length <= 2000000 <= height[i] <= 10^9- Every contamination value is either
0or1.
Source note: Interview prompt excerpt preserved as source evidence.