Skip to content

Conversation

@aastikdas
Copy link

We need to calculate how much water can be trapped between bars of different heights after raining.
Approach (Prefix–Suffix / Auxiliary Arrays Method)

The main idea is: For each element, the amount of water that can be trapped above it depends on The maximum height to its left and the maximum height to its right

Water trapped at that position = min(maxLeft, maxRight) - height[i]

So, we first precompute two arrays:
left[i] → highest bar from the start to index i
right[i] → highest bar from the end to index i
Then, for every index i, we find: water[i] = min(left[i], right[i]) - height[i]
Add up all these values to get the total trapped water.

ruturaj-gh and others added 30 commits September 28, 2023 18:02
added shell sort code
…st-element-in-array

Added Program To Find Smallest Element in an Array
i have added this issue please merge this
Finding the Longest Palindrome in an Array
issue resolved of removing duplicates from an array
Issue resolved of finding that arrays are disjoint or not
Calculate the sum of elements in an array
solved issue Nikhil-2002#7 .please have a look
Revert "Finding the Longest Palindrome in an Array"
…ubsequence_length

Longest palindrome subsequence length
turtle game to moving turtle using arrow keys.
Alisha-786 and others added 29 commits October 20, 2023 11:54
Created a Merge Sort Program in C
Create Minimum Sum of Four Digit Number After Splitting Digits
added kadans algorithm and unique element in array code in cpp
Create maximum-product-of-two-elements-in-an-array
Create count-the-number-of-complete-components
Create-take-input-in-string-form-and-convert-to-array-format-for-operation Nikhil-2002#98
Created  CONTRIBUTING.md for the project
…ctor

Added F1 Race Predictor program for Hacktoberfest 2025
@aastikdas
Copy link
Author

Please @Nikhil-2002 label it as "hacktoberfest" and "hacktoberfest-accepted."
Thank you for providing the repo; it was a great boost for a beginner like me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.