-
Notifications
You must be signed in to change notification settings - Fork 2
feat(algorithms, greedy): largest palindromic number #156
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, greedy): largest palindromic number #156
Conversation
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAdds a new "Largest Palindromic Number" solution with two implementations, README, and tests to the greedy algorithms; removes an unreachable return in the buy/sell stock DP module; updates DIRECTORY.md to include the new subsection. Changes
Sequence Diagram(s)(Skipped — changes are algorithmic within modules and do not introduce multi-component control flow.) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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. 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: 3
🤖 Fix all issues with AI agents
In `@algorithms/greedy/largest_palindromic_number/__init__.py`:
- Around line 46-65: The middle-digit selection loop currently iterates digits
with "for digit in range(9, 0, -1)" which skips '0' and causes wrong results for
inputs where 0 is the only odd-count digit; update the loop to include 0 (e.g.,
range(9, -1, -1) or otherwise fall back to checking digit '0') so that
digit_counter['0'] can be chosen as result when appropriate, and remember to
decrement digit_counter[digit_str] when you pick '0' just like for other digits;
keep the subsequent symmetric-pair logic (the number loop that divides counts by
two and builds temp/result) unchanged and ensure final return still uses
result.strip("0") or "0".
In `@algorithms/greedy/largest_palindromic_number/README.md`:
- Line 63: Update the time complexity sentence in the README.md (the line
stating "The time complexity of the solution is O(n), where n is the length of
the nums string.") to replace "nums string" with "num string" so it reads
"...where n is the length of the num string."
In `@DIRECTORY.md`:
- Around line 144-145: The markdown list indentation is inconsistent for the
"Largest Palindromic Number" entry and its test link; update the second bullet
(the line starting with "[Test Largest Palindromic
Number](https://github.com/.../test_largest_palindromic_number.py)") to the
correct nesting level by indenting it to match the configured list nesting (use
the same number of spaces as other sub-items, e.g., two spaces) so the "Largest
Palindromic Number" header and its test link have consistent indentation and
satisfy MD007.
🧹 Nitpick comments (1)
algorithms/greedy/largest_palindromic_number/test_largest_palindromic_number.py (1)
8-16: Add regression case for odd‑zero middle.Include a case like
("11000", "10001")so both implementations are guarded against skipping0as the middle digit.✅ Test case addition
LARGEST_PALINDROMIC_NUMBER_TEST_CASES = [ ("2012", "212"), ("000001", "1"), ("111222333", "3213123"), ("000000", "0"), ("123456789123456789", "987654321123456789"), ("444947137", "7449447"), ("00009", "9"), + ("11000", "10001"), ]
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Describe your change:
Adds algorithm for finding largest palindromic number from a given number string with digits from 0 to 9
Checklist:
Fixes: #{$ISSUE_NO}.Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.