Skip to content

Conversation

Ruturaj-007
Copy link

Summary

This PR adds a new utility class ValidParentheses that checks if a given string of parentheses is valid.
It supports '()', '{}', and '[]' and ensures correct nesting and ordering.

Features

  • isValid(String str) checks if the input string has valid parentheses.
  • Comprehensive JUnit tests included in ValidParenthesesTest.
  • Covers both valid and invalid cases, including empty strings.

Testing

All tests have been verified locally and passed successfully.

Tests Passed

References

This contribution follows the repository’s naming conventions and code style.

@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2025

Codecov Report

❌ Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.80%. Comparing base (f0fb971) to head (de37275).

Files with missing lines Patch % Lines
...ava/com/thealgorithms/stacks/ValidParentheses.java 81.25% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6734      +/-   ##
============================================
- Coverage     76.80%   76.80%   -0.01%     
- Complexity     6047     6054       +7     
============================================
  Files           719      720       +1     
  Lines         20342    20358      +16     
  Branches       3940     3945       +5     
============================================
+ Hits          15624    15635      +11     
- Misses         4127     4130       +3     
- Partials        591      593       +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.

@Ruturaj-007 Ruturaj-007 force-pushed the feat/valid-parentheses branch from ad030d1 to 3d3f61a Compare October 11, 2025 16:30
@Ruturaj-007
Copy link
Author

Ruturaj-007 commented Oct 11, 2025

Hi @DenizAltunkapan, @yanglbme, and @alxkm

All linter issues (Checkstyle, PMD, Clang format) have been fixed.
ValidParentheses now uses Deque and all if statements have braces to satisfy Checkstyle.
JUnit tests cover valid, invalid, and null inputs.
Patch coverage is currently 81.25%; additional edge-case tests can be added if needed.

Looking forward to your review!

@alxkm
Copy link
Member

alxkm commented Oct 12, 2025

@Ruturaj-007
Copy link
Author

Thanks for pointing that out, @alxkm!
I noticed there’s already a ValidParentheses class under com.thealgorithms.strings, but my implementation is placed under com.thealgorithms.stacks, emphasizing the stack-based approach to solving the problem.

This version also enforces the utility class pattern, satisfies PMD and Checkstyle rules, and focuses on algorithmic demonstration rather than input validation.

If preferred, you may merge these improvements into the existing one or move this implementation to a more suitable location.

I'm grateful for this experience!

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