-
Notifications
You must be signed in to change notification settings - Fork 2
feat(algorithms, two-pointers): valid palindrome with one character removal #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(algorithms, two-pointers): valid palindrome with one character removal #148
Conversation
📝 WalkthroughWalkthroughThe changes reorganize palindrome-related code from the Pystrings module to Two Pointers, introduce a new algorithm to validate palindromes with up to one character removal, update all import paths accordingly, and apply formatting updates to documentation files. Changes
Poem
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @algorithms/two_pointers/palindrome/README.md:
- Around line 250-252: Typo fix: update the README description for
is_valid_palindrome_with_one_char_removal to read "left_pointer at the start and
right_pointer at the end of the string" (add the missing article "the"); locate
the sentence that mentions left_pointer and right_pointer and insert "the"
before "end of the string" so the phrase becomes "at the end of the string".
In @DIRECTORY.md:
- Around line 221-232: The markdown list under the "Palindrome" section has
inconsistent indentation causing MD007 (ul-indent) errors; fix by aligning the
nesting to match the Two Pointers pattern: indent the "Palindrome" header 4
spaces, its direct children ("Largest Palindrome Product", "Longest Palindrome",
"Longest Palindromic Substring", "Palindrome Index", "Palindrome Pairs",
"Permutation Palindrome", "Test Palindrome", etc.) 6 spaces, and any test
sub-items (e.g., "Test Largest Palindrome Product", "Test Permutation
Palindrome", "Test Palindrome Index", "Test Palindrome Pairs") 8 spaces so the
list matches the surrounding sections and passes markdownlint-cli2.
🧹 Nitpick comments (2)
tests/pystrings/test_longest_palindrome.py (1)
18-24: Consider renaming test method to match the function being tested.The method
test_longest_palindrome_two(line 18) actually testslongest_palindrome_one(line 21). While this appears to be a pre-existing issue not introduced by this PR, consider renaming for clarity.Suggested rename
- def test_longest_palindrome_two(self): + def test_longest_palindrome_one_single_char(self): """Should return 1 for s = a""" s = "a" actual = longest_palindrome_one(s)algorithms/two_pointers/palindrome/test_palindrome.py (1)
144-160: Good test coverage. Consider adding edge case tests.The test cases cover a good variety of scenarios. Optionally, consider adding edge cases for completeness:
Suggested additional test cases
IS_PALINDROME_WITH_ONE_CHAR_REMOVAL_TEST_CASES = [ + ("a", True), # Single character - always valid + ("ab", True), # Two different chars - remove one + ("aa", True), # Two same chars - already palindrome ("aba", True), ("abca", True), ("abc", False), ("abccbxa", True), ("madame", True), ("dead", True), ("tebbem", False), ("eeccccbebaeeabebccceea", False), ]
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (9)
algorithms/two_pointers/palindrome/images/solutions/is_valid_palindrome_with_one_char_removal_solution_1.pngis excluded by!**/*.pngalgorithms/two_pointers/palindrome/images/solutions/is_valid_palindrome_with_one_char_removal_solution_2.pngis excluded by!**/*.pngalgorithms/two_pointers/palindrome/images/solutions/is_valid_palindrome_with_one_char_removal_solution_3.pngis excluded by!**/*.pngalgorithms/two_pointers/palindrome/images/solutions/is_valid_palindrome_with_one_char_removal_solution_4.pngis excluded by!**/*.pngalgorithms/two_pointers/palindrome/images/solutions/is_valid_palindrome_with_one_char_removal_solution_5.pngis excluded by!**/*.pngalgorithms/two_pointers/palindrome/images/solutions/is_valid_palindrome_with_one_char_removal_solution_6.pngis excluded by!**/*.pngalgorithms/two_pointers/palindrome/images/solutions/is_valid_palindrome_with_one_char_removal_solution_7.pngis excluded by!**/*.pngalgorithms/two_pointers/palindrome/images/solutions/is_valid_palindrome_with_one_char_removal_solution_8.pngis excluded by!**/*.pngalgorithms/two_pointers/palindrome/images/solutions/is_valid_palindrome_with_one_char_removal_solution_9.pngis excluded by!**/*.png
📒 Files selected for processing (20)
DIRECTORY.mdalgorithms/backtracking/partition_string/__init__.pyalgorithms/greedy/jump_game/README.mdalgorithms/two_pointers/palindrome/README.mdalgorithms/two_pointers/palindrome/__init__.pyalgorithms/two_pointers/palindrome/largest_palindrome_product/README.mdalgorithms/two_pointers/palindrome/largest_palindrome_product/__init__.pyalgorithms/two_pointers/palindrome/largest_palindrome_product/test_largest_palindrome_product.pyalgorithms/two_pointers/palindrome/longest_palindrome.pyalgorithms/two_pointers/palindrome/longest_palindromic_substring.pyalgorithms/two_pointers/palindrome/palindrome_index.pyalgorithms/two_pointers/palindrome/palindrome_pairs.pyalgorithms/two_pointers/palindrome/permutation_palindrome/README.mdalgorithms/two_pointers/palindrome/permutation_palindrome/__init__.pyalgorithms/two_pointers/palindrome/permutation_palindrome/test_permutation_palindrome.pyalgorithms/two_pointers/palindrome/test_palindrome.pyalgorithms/two_pointers/palindrome/test_palindrome_index.pyalgorithms/two_pointers/palindrome/test_palindrome_pairs.pydatastructures/trees/binary/README.mdtests/pystrings/test_longest_palindrome.py
🧰 Additional context used
🧬 Code graph analysis (3)
algorithms/backtracking/partition_string/__init__.py (1)
algorithms/two_pointers/palindrome/__init__.py (1)
is_palindrome(1-52)
tests/pystrings/test_longest_palindrome.py (1)
algorithms/two_pointers/palindrome/longest_palindrome.py (2)
longest_palindrome_one(19-53)longest_palindrome_two(56-96)
algorithms/two_pointers/palindrome/test_palindrome.py (1)
algorithms/two_pointers/palindrome/__init__.py (1)
is_valid_palindrome_with_one_char_removal(167-206)
🪛 markdownlint-cli2 (0.18.1)
DIRECTORY.md
221-221: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
222-222: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
223-223: Unordered list indentation
Expected: 6; Actual: 8
(MD007, ul-indent)
224-224: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
225-225: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
226-226: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
227-227: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
228-228: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
229-229: Unordered list indentation
Expected: 6; Actual: 8
(MD007, ul-indent)
230-230: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
231-231: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
232-232: Unordered list indentation
Expected: 4; Actual: 6
(MD007, ul-indent)
🔇 Additional comments (8)
algorithms/greedy/jump_game/README.md (1)
70-87: Documentation formatting improvements approved.Wrapping variable names and code expressions in backticks enhances readability and clearly distinguishes code elements from explanatory text. These formatting enhancements support better documentation clarity.
datastructures/trees/binary/README.md (1)
39-44: Documentation formatting and clarity improvements approved.Adding inline code formatting around pointers and conditions (
ptr1,ptr2,ptr1.parent, etc.) and ensuring precise punctuation placement within code notation improves the documentation's clarity and technical accuracy.DIRECTORY.md (1)
221-232: Verify all referenced palindrome files exist in the repository.The reorganization introduces multiple new entries and test file references under
algorithms/two_pointers/palindrome/. Ensure that all paths listed are accurate and that corresponding files exist in the repository structure, particularly:
algorithms/two_pointers/palindrome/longest_palindrome.pyalgorithms/two_pointers/palindrome/longest_palindromic_substring.pyalgorithms/two_pointers/palindrome/palindrome_index.pyalgorithms/two_pointers/palindrome/palindrome_pairs.pyalgorithms/two_pointers/palindrome/test_palindrome.pytests/pystrings/test_longest_palindrome.py (1)
3-6: LGTM!Import path correctly updated to reflect the new module location under
algorithms.two_pointers.palindrome.algorithms/backtracking/partition_string/__init__.py (1)
2-2: LGTM!Import path correctly updated to reference
is_palindromefrom the newalgorithms.two_pointers.palindromemodule.algorithms/two_pointers/palindrome/__init__.py (1)
167-206: LGTM! Well-implemented two-pointer algorithm.The implementation correctly handles the Valid Palindrome II problem with O(n) time and O(1) space complexity. The nested
is_substring_palindromehelper appropriately capturessfrom the enclosing scope.One minor note: an empty string input (
"") will returnTruesince the loop condition fails immediately. This behavior seems acceptable given the problem constraints state1 <= s.length, but consider adding an explicit check or doctest if empty string handling is important.algorithms/two_pointers/palindrome/test_palindrome.py (1)
6-14: LGTM!Import paths correctly updated to reference the new module location, and the new
is_valid_palindrome_with_one_char_removalfunction is properly imported for testing.algorithms/two_pointers/palindrome/README.md (1)
261-270: All referenced image files exist. Verification confirms that all 9 solution images are present at the specified paths in the repository.
Describe your change:
Algorithm to check if a string is a valid palindrome if at most one character is removed
Checklist:
Fixes: #{$ISSUE_NO}.Summary by CodeRabbit
New Features
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.