Kumar-laxmi / Algorithms

A Repository for algorithms in C, C++, Python and Java
Apache License 2.0
326 stars 367 forks source link

Trapping Rain Water #1692

Closed Devchawla2608 closed 1 year ago

Devchawla2608 commented 1 year ago

Is your feature request related to a problem? Please describe. The Trapping Rain Water problem is used to calculate the amount of water that can be trapped between bars in a histogram-like structure. The problem statement typically provides an array representing the heights of the bars. The task is to determine the total amount of water that can be trapped between the bars.

Describe the solution you'd like 1.) Initialize variables leftMax and rightMax to store the maximum heights of bars on the left and right sides 2.) Initialize variables left and right to point to the first and last elements of the array. 3.) Initialize a variable ans to store the total trapped water, initially set to 0. 4.) While left is less than or equal to right 5.) If the height of the bar at index left is less than or equal to the height of the bar at index right 6.) If the height of the bar at index left is greater than leftMax, update leftMax with the current height. 7.) Otherwise, calculate the trapped water at the left index by subtracting the height of the bar at left from leftMax, and add the result to ans. 8.) Increment left by 1. 9.) Otherwise, do the same steps as above but with right instead of left. 10.) Return the value of ans as the total amount of trapped water.

image

Devchawla2608 commented 1 year ago

@Kumar-laxmi please assign this to me under SSOC'23. I'm ready to contribute in all 4 languages

khushboo-9876 commented 1 year ago

hey ,is this issue availabe please assign me

Kumar-laxmi commented 1 year ago

Don't raise issues to solve the interview questions