Skip to content

Conversation

@AliAlimohammadi
Copy link
Contributor

Description

Adds a dynamic programming solution for finding the minimum cuts needed for palindrome partitioning of a string.

Algorithm

Given a string s, partition s such that every substring of the partition is a palindrome. This function finds the minimum number of cuts needed for such a partitioning.

Time Complexity: O(n²)
Space Complexity: O(n²)

Example

assert_eq!(minimum_palindrome_partitions("aab"), 1);    // "aa" | "b"
assert_eq!(minimum_palindrome_partitions("aaa"), 0);    // Already palindrome
assert_eq!(minimum_palindrome_partitions("ababbbabbababa"), 3);

Implementation Details

  • Uses dynamic programming with memoization
  • Maintains a 2D boolean matrix to track palindromic substrings
  • Tracks minimum cuts needed for each position
  • Handles Unicode strings properly using Vec<char>

Testing

  • All existing tests pass
  • Added comprehensive test suite covering:
    • Basic cases
    • Edge cases (empty string, single character)
    • Already palindromic strings
    • Non-palindromic strings
    • Longer test cases

Reference

Based on: https://www.youtube.com/watch?v=_H8V5hJUGd0

Checklist

  • Code follows the repository's style guidelines
  • Self-review performed
  • Code is well-commented
  • Tests added and passing
  • Documentation added

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.65%. Comparing base (98400e1) to head (48efcd7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #971      +/-   ##
==========================================
+ Coverage   95.64%   95.65%   +0.01%     
==========================================
  Files         344      345       +1     
  Lines       22526    22569      +43     
==========================================
+ Hits        21544    21589      +45     
+ Misses        982      980       -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.

@AliAlimohammadi
Copy link
Contributor Author

@siriak, this is ready to be merged.

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak siriak merged commit 5c4593c into TheAlgorithms:master Dec 17, 2025
7 checks passed
@AliAlimohammadi AliAlimohammadi deleted the add-palindrome-partitioning branch December 17, 2025 21:05
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