Skip to content

Implementation of the "TRAPPING RAINWATER PROBLEM" in C++ #372

@chandradeep12

Description

@chandradeep12

Description

Implement the Trapping Rainwater Problem in C++.
Given an array representing the height of bars, calculate how much water can be trapped between them after it rains.
This is a classic array-based problem that helps in understanding prefix-suffix logic and the two-pointer approach.

Problem Statement

You are given an array height[] where each element represents the height of a bar.
The width of each bar is 1 unit.
Find the total amount of rainwater that can be trapped after raining.

Example

Input:
height[] = {4, 2, 0, 3, 2, 5}

Output:
9

Explanation:
Total trapped rainwater = 9 units

Expected Approach

Implement both brute-force and optimized (O(n)) solutions

Use two-pointer or prefix-suffix logic

Take user input dynamically

Display total trapped water clearly

hey @xthxr
If this issue is assigned, please label it under "hacktoberfest" tag....
Thank you.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions