SarthakKeshari / CPP-Questions-and-Solutions

This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
MIT License
47 stars 132 forks source link

trappingRainWater.cpp #525

Closed YashGosaliya closed 2 years ago

YashGosaliya commented 2 years ago

Choose your form and fill it -

1. Form 1(C++ Solution contributors)

2. Form 2(C++ Documentation Contributors)


1) Form 1

Issue Id you have worked upon -

521

Briefly explain your program logic -

--> Consider from left (first element) to right (last element). --> Check until the left element is less than or equal to the right element. --> Comparing heights from both left and right sides. --> We are checking if the height at left is greater than or equal to the maximum height at left then we add the difference of their heights in the total units, same applied for the right side. --> Return the total units of rainwater trapped by these bars.

Screenshots(Attach 2 screenshots of your own input and output) -

Input

Screenshot (70)

Output ![Screenshot (71)](https://user-images.githubusercontent.com/58128160/138213020-f38d4d8f-46c3-4af8-b5e3-3d0c1b8be7a5.png) ### Checklist: Eg - If your code follow the below guidelines. Kindly change [] to [x] All the conditions should be fulfilled for considering your code for merging - - [x] I have mentioned the question as comment in my solution file.
- [x] My code follows the guidelines of this project.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code.
- [x] My code gives the correct output.
- [x] I confirm that I have not copied the code from anywhere. In case its found that I have copied even after successful merge then I can be banned from the repository and hacktoberfest.
- [x] I affirm that I strictly follow contributing guidelines and code of conduct.
# 2) Form 2 ### Issue Id you have worked upon - Kindly write your answer here
### Checklist: Eg - If your code follow the below guidelines. Kindly change [] to [x] All the conditions should be fulfilled for considering your Pull Request for merging - - [] I have performed a self-review of my documentation.
- [] I affirm that I strictly follow contributing guidelines and code of conduct.