Usable Water with Contaminated Pillars
Updated
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.
More Infosys Online Assessment questions
- At Most K Jumps with Quadratic Transition CostOA · Seen Nov 2026
- Hiking Club Fastest PaceOA · Seen Nov 2026
- Lowest Common Ancestor with a Changing RootOA · Seen Nov 2026
- Minimum Leaf Path Sum over All RootsOA · Seen Nov 2026
- Split Array to Minimize the Largest SumOA · Seen Nov 2026
- Cherry PickupOA · Seen Nov 2026
- Lexicographically Smallest Grid Path with One Letter ChangeOA · Seen Nov 2026
- Minimum Cost to Supply Water with Wells and PipesOA · Seen Nov 2026
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3OA · Seen Nov 2026
- Minimum Rounds to Complete All TasksOA · Seen Nov 2026
Similar questions at other companies
- Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
- Garden Sprinkler PlacementAirbnb · OAAirbnb interview questions
- Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Minimum Last-Element RelocationsChubb · OAChubb interview questions
- Generating Login CodesSnowflake · OASnowflake interview questions
- Paint the CeilingWeRide · OAWeRide interview questions
- Rotate an Array In PlaceAdobe · OA · PHONE SCREENAdobe interview questions
- Minimum Adjacent Merges to Form a PalindromeArista Networks · OAArista Networks interview questions