feat(algorithms, stack): longest valid parentheses#191
Conversation
📝 WalkthroughWalkthroughA new stack-based algorithm for finding the longest valid parentheses substring has been added to the algorithms collection, including implementation, comprehensive documentation, and unit tests across four files. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
algorithms/stack/longest_valid_parentheses/__init__.py (1)
1-1: Consider adding a function docstring with doctest examples.This would improve discoverability and keep the new algorithm self-documented at source level.
🧩 Suggested enhancement
def longest_valid_parentheses(s: str) -> int: + """ + Return the length of the longest valid parentheses substring. + + >>> longest_valid_parentheses("(()") + 2 + >>> longest_valid_parentheses(")()())") + 4 + >>> longest_valid_parentheses("") + 0 + """🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@algorithms/stack/longest_valid_parentheses/__init__.py` at line 1, Add a concise docstring to the function longest_valid_parentheses describing its purpose, parameters, and return value, and include several doctest-style examples showing expected outputs (e.g., empty string -> 0, "()" -> 2, ")()())" -> 4, "(()" -> 2) to serve as usage documentation and tests; place the docstring immediately under the def longest_valid_parentheses(s: str) -> int: signature and ensure examples use Python REPL format (>>> ...) so they can be run by doctest.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@algorithms/stack/longest_valid_parentheses/README.md`:
- Line 73: Reword the final-step sentence to reflect that max_length is
maintained during the loop and is the final answer (rather than implying a
separate final max(maxLength, currentLength) call); mention that max_length is
updated on each iteration (e.g., via max_length = max(max_length,
current_length)) and the final result is simply max_length after the iteration
completes.
---
Nitpick comments:
In `@algorithms/stack/longest_valid_parentheses/__init__.py`:
- Line 1: Add a concise docstring to the function longest_valid_parentheses
describing its purpose, parameters, and return value, and include several
doctest-style examples showing expected outputs (e.g., empty string -> 0, "()"
-> 2, ")()())" -> 4, "(()" -> 2) to serve as usage documentation and tests;
place the docstring immediately under the def longest_valid_parentheses(s: str)
-> int: signature and ensure examples use Python REPL format (>>> ...) so they
can be run by doctest.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 26696d09-c053-4342-9d4a-807679d03054
📒 Files selected for processing (4)
DIRECTORY.mdalgorithms/stack/longest_valid_parentheses/README.mdalgorithms/stack/longest_valid_parentheses/__init__.pyalgorithms/stack/longest_valid_parentheses/test_longest_valid_parentheses.py
Describe your change:
Finds the longest valid parentheses using a stack data structure
Checklist:
Fixes: #{$ISSUE_NO}.Summary by CodeRabbit
Release Notes
New Features
Documentation
Tests