Data Structures & AlgorithmsHardAmazon OA · Arrays

The bars of a histogram-shaped terrain have heights [4, 2, 0, 3, 2, 5]. After rain, how many units of water are trapped between the bars?

  1. A. 7
  2. B. 8
  3. C. 9
  4. D. 11

Correct answer: C. 9

Water above bar i = min(max to the left, max to the right) - height: 0 + 2 + 4 + 1 + 2 + 0 = 9.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic