Skip to content

Conversation

@Arzoo1701
Copy link

Description

This PR adds an implementation of the Trapping Rainwater problem using the Two Pointer approach under src/main/java/com/thealgorithms/searches.

Problem Statement

Given an array of non-negative integers representing elevation map heights, compute how much water can be trapped after raining.

Example

Input: [4, 2, 0, 3, 2, 5]
Output: 9

Approach

  • Used Two Pointer Technique to achieve O(n) time and O(1) space complexity.
  • Added detailed Javadoc comments including reference to the official explanation:
    Wikipedia – Trapping Rain Water

Related Issue

Fixes #6876

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.34%. Comparing base (0837424) to head (76ff418).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...va/com/thealgorithms/stacks/TrappingRainwater.java 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #6990   +/-   ##
=========================================
  Coverage     78.34%   78.34%           
- Complexity     6621     6644   +23     
=========================================
  Files           747      749    +2     
  Lines         22036    22118   +82     
  Branches       4322     4344   +22     
=========================================
+ Hits          17264    17329   +65     
- Misses         4085     4092    +7     
- Partials        687      697   +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Arzoo1701
Copy link
Author

Hi @alxkm @yanglbme @DenizAltunkapan 👋
All checks have passed for this PR.
Kindly review when you get a chance — thank you! 🙏

Copy link
Member

@DenizAltunkapan DenizAltunkapan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arzoo1701 Please always add a corresponding test class if you're adding a new algorithm/class. Thank you for your contribution.

@Arzoo1701
Copy link
Author

@Arzoo1701 Please always add a corresponding test class if you're adding a new algorithm/class. Thank you for your contribution.

@DenizAltunkapan The requested test class has been added and all checks have passed. Please review and merge when possible. Thank you!

@DenizAltunkapan
Copy link
Member

@Arzoo1701 are you sure that both classes should stay in the search package? it seems that this is not a search algorithm

@Arzoo1701
Copy link
Author

Arzoo1701 commented Oct 31, 2025

@DenizAltunkapan
The branch has been updated with the latest main changes.
The Trapping Rain Water algorithm and corresponding test class have been moved to the correct stacks package.
All tests for the Trapping Rain Water algorithm pass .

@Arzoo1701 Arzoo1701 force-pushed the add-trapping-rainwater branch from 19be1e2 to b959623 Compare November 1, 2025 19:47
Copy link
Member

@DenizAltunkapan DenizAltunkapan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arzoo1701 Arzoo1701 force-pushed the add-trapping-rainwater branch from b8ed7b0 to 76ff418 Compare November 3, 2025 14:19
@DenizAltunkapan
Copy link
Member

there is still a changed line in the pom.xml @Arzoo1701

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.

[FEATURE REQUEST] Add Trapping Rainwater problem in searches section (Java)(Hacktoberfest)

3 participants