Skip to content

Conversation

@BrianLusina
Copy link
Owner

@BrianLusina BrianLusina commented Jan 21, 2026

Describe your change:

Adds algorithm for finding largest palindromic number from a given number string with digits from 0 to 9

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Summary by CodeRabbit

  • New Features

    • Added "Largest Palindromic Number" problem with two alternative implementations.
  • Bug Fixes

    • Removed unreachable dead code from an existing stock algorithm.
  • Documentation

    • Added a detailed problem README with algorithm outline, edge cases, and complexity notes.
    • Updated directory index to include the new problem.
  • Tests

    • Added parameterized test suite validating both implementations.

✏️ Tip: You can customize this high-level summary in your review settings.

@BrianLusina BrianLusina self-assigned this Jan 21, 2026
@BrianLusina BrianLusina added enhancement Algorithm Algorithm Problem Documentation Documentation Updates Strings Greedy Greedy Algorithm labels Jan 21, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 21, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Largest Palindromic Number Implementation
algorithms/greedy/largest_palindromic_number/__init__.py
Adds largest_palindromic_number() and largest_palindromic_number_v2() to build the largest palindrome from digit counts, handling leading-zero and all-zero edge cases.
Documentation
algorithms/greedy/largest_palindromic_number/README.md, DIRECTORY.md
New README documenting problem, algorithm, examples, complexity; DIRECTORY.md updated to include the new subsection under greedy.
Tests
algorithms/greedy/largest_palindromic_number/test_largest_palindromic_number.py
New parameterized unittest suite validating both implementations against multiple cases.
Cleanup
algorithms/dynamic_programming/buy_sell_stock/__init__.py
Removed an unreachable return 0 (dead code) from max_profit_two_pointers.

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

🐰 I counted digits, hopped with glee,

Pairs and a center, symmetrical spree.
From nine down, I stitched a mirror true,
A largest palindrome, born anew —
Hooray for hops that code can do! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a new greedy algorithm for finding the largest palindromic number.
Description check ✅ Passed The description provides a clear summary of the change and includes a completed checklist covering all required contribution guidelines.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 skipping 0 as 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>
@BrianLusina BrianLusina merged commit 0b0c41e into main Jan 21, 2026
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Algorithm Algorithm Problem Documentation Documentation Updates enhancement Greedy Greedy Algorithm Strings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants