#1278
Palindrome Partitioning III
expert · 1130 · lc hard +32 · verified · 62.2% accepted · 1,210 likes · top 63%
Description
Given a lowercase string s and an integer k, perform these two steps:
1. Optionally change any characters in s to other lowercase letters.
2. Split s into exactly k non-empty, non-overlapping substrings such that each one is a palindrome.
Return the minimum number of character changes needed to accomplish this.
Example 1:
Input: s = "abc", k = 2
Output: 1
Explanation: You can split the string into "ab" and "c", and change 1 character in "ab" to make it palindrome.
Example 2:
Input: s = "aabbc", k = 3
Output: 0
Explanation: You can split the string into "aa", "bb" and "c", all of them are palindrome.
Example 3:
Input: s = "leetcode", k = 8
Output: 0
Code
1
2
3