ankitapuri / DSA-guide

Trying to cover important DSA
MIT License
49 stars 113 forks source link

Rain Water problem solved in python #267

Closed abhinav5481 closed 3 years ago

abhinav5481 commented 3 years ago

Related Issue:

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much waterContent it is able to trap after raining.

Closes: #254

Describe the changes you've made

Logic: An element of the array can store waterContent if there are higher bars on left and right. The amount of waterContent to be stored in every element can be found out by finding the heights of bars on the left and right sides.

Approach: Traverse the element of the array one by one and find the largest element on the left as well as on the right-hand side. The difference between the smaller of two sides & the current element would give the amount of waterContent stored.

Algorithm:

Type of change

How Has This Been Tested?

It has been tested on my local machine.

Describe if there is any unusual behaviour of your code(Write NA if there isn't)

Na

Checklist:

Screenshots

Original Updated
original screenshot updated screenshot

image

Please review my code & let me know if any further changes are required.

ankitapuri commented 3 years ago

rest all i good to go but kindly take user input

abhinav5481 commented 3 years ago

Done. image