Palindrome Partitioning III

HardDynamic Programminginterval dp

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given a lowercase string s and an integer k. You may first change any characters of s to other lowercase letters, and then you must split s into exactly k non-empty consecutive pieces, each of which is a palindrome. Return the minimum number of characters you need to change.

Examples

Input: s = "abc", k = 2
Output: 1
Split into "ab" and "c"; changing one character of "ab" makes it a palindrome.
Input: s = "aabbc", k = 3
Output: 0
"aa", "bb", "c" are already palindromes.
Input: s = "leetcode", k = 8
Output: 0
Every single character is a palindrome.

Constraints

  • 1 <= k <= s.length <= 100
  • s consists of lowercase English letters

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More interval dp problems