What will be the maximum water that can be collected between 2 bars if we remove all the bars between them?

What will be the maximum water that can be collected between 2 bars if we remove all the bars between them?

Now you have to pick two bars and remove the bars between them such that when rain falls the water collected between two bars is maximum. Note that the distance between bars remains the same after removing the remaining bars. 2. [3 16 10 5 6 12 20 18] ans: 80 (16*(number of integers between 16 and 18)).

Can you drink rain water?

Avoid using rainwater for drinking, cooking, brushing your teeth, or rinsing or watering plants that you intend to eat. Instead, use municipal tap water if it is available, or purchase bottled water for these purposes.

Do you need to filter rainwater?

Tips for improving the safety of rainwater According to the Centers for Disease Control and Prevention (CDC), rainwater that’s collected for drinking purposes should be filtered, disinfected, and tested regularly ( 2 ).

How much water is collected between the towers?

I recently came across an interview question asked by Amazon and I am not able to find an optimized algorithm to solve this question: You are given an input array whose each element represents the height of a line towers. The width of every tower is 1. It starts raining. How much water is collected between the towers?

What is the maximum amount of water between two buildings?

Water between the buildings of height 1 and height 4 = 1. Water between the buildings of height 3 and height 4 = 0. Hence maximum of all the cases is 1. Recommended: Please try your approach on {IDE} first, before moving on to the solution.

How to calculate the amount of water accumulated in a building?

You can traverse first from left to right, and calculate the water accumulated for the cases where there is a smaller building on the left and a larger one on the right. You would have to subtract the area of the buildings that are in between these two buildings and are smaller than the left one.

When do you trap water in a tower?

For the remaining towers, they can trap water when there are max heights to the left and to the right. water accumulation is: max ( min (max_left, max_right) – current_height, 0 ) Iterating from the left, if we know that there is a max_right that is greater, min (max_left, max_right) will become just max_left.