pyassistant

Minimize edits to split string into m palindromes

Given a string s and an integer m, partition s into exactly m non-empty contiguous substrings and change the minimum number of characters so that every substring becomes a palindrome. Return the minimum number of character changes required and one resulting list of the m palindromic substrings obtained after applying those changes. If it is impossible to partition s into exactly m non-empty parts (i.e., m > len(s) or m <= 0), return (-1, []).

Example:

Input:
("abcbaefg", 2)
Output:
(1, ['abcba', 'efe'])

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.