Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Trapping Rain Water (Main Thread)

Here is the interview question prompt, presented for reference.

The Trapping Rain Water Challenge: A Deep Dive

Imagine you're looking at an elevation map displaying rainfall over a region's landscape. The map consists of bars of varying heights, each representing different elevations. Can you determine the amount of rainwater that this uneven terrain can hold?

![Elevation Map](https://storage.googleapis.com/algodailyrandomassets/curriculum/stacks/rain0.png)

Problem Setup

We'll simplify the problem by using a one-dimensional array of non-negative integers. Each integer represents the height of the land at different points. The objective is to calculate the volume of rainwater that can be trapped by this series of elevations.

To better visualize this, consider the diagram below, which illustrates various elevation maps and the potential rainwater they can hold. Think of it like a game of Tetris; we aim to find how many units of rainwater could be accommodated in the available gaps.

![Rainwater in Elevation Maps](https://storage.googleapis.com/algodailyrandomassets/curriculum/stacks/rain1.png)

Constraints and Performance Metrics

  • Length of the array <= 100000
  • Values in the array >=0
  • The final answer would fit in the Integer range(< 2^32)
  • Expected time complexity : O(n)
  • Expected space complexity : O(1)

You can see the full challenge with visuals at this link.

Challenges • Asked over 6 years ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Nov 30, 2017:

This is the main discussion thread generated for Trapping Rain Water.

bsanneh Commented on Jan 02, 2021:

There are no test cases and the environment does not support python

Jake from AlgoDaily Commented on Jan 02, 2021:

Thanks for the heads up and sorry for the miss! Added to the queue for the team to address, will update when resolved.

bsanneh Commented on Jan 02, 2021:

Thank you

Jake from AlgoDaily Commented on Jan 04, 2021:

Updated and resolved :-)