Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional

Problem: Water fills a 1-dimensional container with walls of heights [4, 1, 3, 1, 2]. Each cell holds water up to the minimum of the tallest wall on its left and right, minus its own height. What is the total water held?

  1. A. 4
  2. B. 2
  3. C. 3
  4. D. 5

Correct answer: C. 3

Each cell's water level is limited by the lower of its two side maxima. The cells at indices 1 and 3 hold 2 and 1 units respectively, so the total is 3.

More Coding Interview Problems questions

Exams that ask this topic