329. Palindrome Partitioning III

HardDynamic Programming

You are given a string `s` containing lowercase letters and an integer `k`. You need to: - First, change some characters of `s` to other lowercase English letters. - Then divide `s` into `k` non-empty disjoint substrings such that each substring is a palindrome. Return the **minimal number of characters** that you need to change to divide the string.

Examples

Input: abc 2

Output: 1

Explanation: Split into 2 palindromic parts, e.g. "a" | "bc"; making "bc" a palindrome costs 1 change.

Constraints

  • 1 <= k <= s.length <= 100
  • s only contains lowercase English letters.
Loading...

Run checks all cases above. Submit evaluates all test cases.