Skip to content

Conversation

@coder-Basundhara
Copy link

Implemented an optimized valid parentheses checker (BalancedBrackets.java) that supports all bracket types: (), [], {}, and <>. The solution handles all edge cases and ensures O(n) time and O(n) space complexity using a stack.

Details:

Edge cases handled:

Empty strings (returns true)

Null input (throws IllegalArgumentException)

Odd-length strings (cannot be balanced)

Strings with non-bracket characters (returns false)

Nested and mixed brackets of any valid combination

Optimizations:

Single pass through the string (O(n) time)

Stack stores only unmatched opening brackets (O(n) space in worst case)

Immediate rejection for unmatched or invalid characters

Testing:

Verified against existing JUnit 5 test cases in BalancedBracketsTest.java

All tests for paired brackets, unbalanced strings, null inputs, and invalid characters pass successfully

Impact:
This implementation ensures that the algorithm is robust, efficient, and ready for use in any project requiring balanced bracket validation.

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2025

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.32%. Comparing base (883a050) to head (a87d5d0).

Files with missing lines Patch % Lines
...ava/com/thealgorithms/stacks/BalancedBrackets.java 86.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6767      +/-   ##
============================================
- Coverage     77.33%   77.32%   -0.01%     
- Complexity     6171     6175       +4     
============================================
  Files           721      721              
  Lines         20589    20589              
  Branches       3992     3992              
============================================
- Hits          15922    15920       -2     
  Misses         4055     4055              
- Partials        612      614       +2     

☔ 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.

@DenizAltunkapan
Copy link
Member

@coder-Basundhara Please fix the failing workflows so I can start the review.

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

This pull request has been automatically closed because its workflows or checks failed and it has been inactive for more than 14 days. Please fix the workflows and reopen if you'd like to continue. Merging from main/master alone does not count as activity.

@github-actions github-actions bot closed this Nov 3, 2025
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.

3 participants