FastPrepUsable Water with Contaminated Pillars
Problems/Usable Water with Contaminated Pillars

Usable Water with Contaminated Pillars

Infosys logoInfosys● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Infosys new grad online assessment. The report describes trapping rainwater with contaminated pillars, where water that touches a contaminated pillar is left out. We read that as water directly above a contaminated index. We also chose a binary representation, limits and a method interface, so the results are fixed. Our version is about 84% the same as the reported question.

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[]) → long

Examples

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 = 4

The 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 = 5

Four of the standard nine units lie above the contaminated index and are excluded.

Constraints

  • 1 <= height.length == contaminated.length <= 200000
  • 0 <= height[i] <= 10^9
  • Every contamination value is either 0 or 1.

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
All Infosys interview questionsSee Infosys hiring insights
Saved
class Solution {
    public long usableTrappedWater(int[] height, int[] contaminated) {
        // Write your code here.
    }

}
Checking account…